program to use prime number is not prime in c language
#include <stdio.h>
#include <math.h>
int main()
{
int i, n;
printf("Enter a number : ");
scanf("%d", &n);
for (i = 2; i <= sqrt(n); i++)
{
if (n % i == 0)
{
break;
}
printf("i=%d\n", i);
printf("n=%d\n", n);
}
if (i > sqrt(n))
{
printf("%d is prime\n", n);
}
else
{
printf("%d is not prime\n", n);
}
return 0;
}
output
Enter a number : 7
i=2
n=7
7 is prime
output
Enter a number : 4
4 is not prime