Here we will write a program to check whether the given number is prime or not using looping.
#include<stdio.h>
int main(){
int n, i, j, count;
printf("Enter the number : ");
scanf("%d",&n);
for(i=1; i<=n; i++)
{ count=0;
for(j=1; j<=n; j++)
{
if(i%j==0)
count++;
}
}
if(count==2)
printf("The no is prime.");
else
printf("Not prime.");
return 0;
}
No comments:
Post a Comment