Program to check whether number is prime or not using functions

Number is prime or not using functions.

Program to check whether number is prime or not using functions.Functions are the building blocks of c++ and place where all programs activity occur.

Calling function from main().

Program to check whether number is prime or not using functions

Program

Using call by value

#include<iostream.h>
#include<conio.h>
void scan (int);
void main()
{
clrscr();
int x;
cout<<"Enter number to check prime or not:- ";
cin>>x;
scan(x);
getch();
}
void scan(int a)
{
 int y=1,i;
 for(i=1;i<=a/2;i++)
 {
  if(a%i==0)
   {
    y++;
   }
 }
 if(y==2)
 {
  cout<<"Entered number is prime ";
}
else
{
 cout<<"Entered number is not prime";
}
}

OUTPUT:-

Program to check whether number is prime or not using functions


Comment below if you are facing any problem and subscribe to our newsletter for more updates.


Also read

C++ Program to find greatest between three numbers using Function
C++ program to swap two numbers using call by value
C++ program of function overloading to calculate area of square and rectangle.


Summary
Program to check whether number is prime or not using functions
Article Name
Program to check whether number is prime or not using functions
Description
Functions are the building blocks of c++ and place where all programs activity occur.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *