Prime number program in c using if else
Prime number program in c using if else:
#include <stdio.h>
int main()
{
int i, j, flag = 0;
printf("Enter the Number: ");
scanf("%d", &i);
for(j = 2; j <= i/2; ++j)
{
if(i%j == 0)
{
flag = 1;
break;
}
}
if (i == 1)
{
printf("1 is neither a prime nor a composite number.");
}
else
{
if (flag == 0)
printf("%d is a prime number.",
i);
else
printf("%d is not a prime
number.", i);
}
return 0;
}
Output:
Enter a number: 4
4 is a not Prime Number.