Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

C program to find the Prime Number in C

#include <stdio.h>

int main()
{
int n, r = 0 ;
printf("Enter number to find the Prime Number\n");
printf("Enter num : ");
scanf("%d",&n);

for (int i=2; i<=n/2; i++)
{
if (n%i == 0)
{
r = 1;
break ;
}
}

if (n == 1)
printf("1 is neither prime nor composite.\n");

else
{
if (r == 0)
printf("%d is a Prime number.\n",n);
else
printf("%d is Not a Prime number.\n",n);
}
return 0;
}