Prime Number : A positive number which is divisible by 1 and number itself is knows as prime number.
For example 7 is prime number because it is divisible by only 1 and number itself(7). While 14 is not prime because it is divisible by 1,2,7, and 14 itself.
Following is a program of prime numbers in c language:
For example 7 is prime number because it is divisible by only 1 and number itself(7). While 14 is not prime because it is divisible by 1,2,7, and 14 itself.
Following is a program of prime numbers in c language:
#include<stdio.h>
int main()
{
int no, i, flag=0;
printf("Enter No : ");
scanf("%d",&no);
for(i=2; i<=no/2; i++)
{
if(no%i == 0)
{
flag = 1;
break;
}
}
if(flag == 1)
printf("Not Prime");
else
printf("Prime");
return 0;
}
int main()
{
int no, i, flag=0;
printf("Enter No : ");
scanf("%d",&no);
for(i=2; i<=no/2; i++)
{
if(no%i == 0)
{
flag = 1;
break;
}
}
if(flag == 1)
printf("Not Prime");
else
printf("Prime");
return 0;
}
0 comments :
Post a Comment