Make function to check prime number by R4R Team

Prime number:
-A number that only divisible by the 1 or by itself is known as prime number.

Example-
prime numbers:
2,3,5,7,11,13,.......
Not prime numbers:
4,8,9,10,.....
-Here we make a function that are able to check the prime number.

program-

#include < stdio.h>
int primecheck(int n)
{
int i;
for(i=2;i< n/2;i++)
{
if(n%i==0)
return 0;
}
return 1;
}
int main()
{
int n;
printf("Enter Number\n");
scanf("%d",&n);
if(primecheck(n))
printf("Prime!");
else
printf("Not prime");
}


output-

Enter Number
12
Not prime

Enter Number
13
Prime!

-In this program, we make a function named as checkprime(int n), we pass an argument which is nothing but an given number.
-So when we pass a number to that function then it try to check the prime or not.
-If number is prime then function will return 1 otherwise it will return 0.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!