Example & Tutorial understanding programming in easy ways.

Write a program to check number is prime or not

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 try to check the given number that it is prime or not.


program-

#include < stdio.h>
int main()
{
int n,i;
printf("Enter Numbern");
scanf("%d",&n);
for(i=2;i< n-1;i++)
{
if(n%i==0)
{
printf("It is not Prime");
n=0;
}
}
if(n!=0)
{
printf("It is a Prime Number");
}
}


output-

Enter Number
12
It is not Prime

Enter Number
13
It is a Prime Number

-In this program, we take an input of the integer number and try to check for prime number.
-We run the loop from i=2 to i=n-1, and divide n by every possible value of i
-If n was divisible by any of these value then it is not prime number otherwise it is prime number.




Read More →
Search
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!