How to write a c program to check whether a number is prime or not ?
Solution:
/*C Program to Check whether the Given Number is a Prime*/
#include <stdio.h>
int main()
{
int i;
int n;
printf("Enter the number: ");
scanf("%d", &n);
for(i = 2; i < n; i++)
{
if(n % i == 0)
{
printf("Not Prime");
break;
}
}
if(i == n)
printf("Prime");
return 0;
}