Source code:
//Write a C program to determine whether a given number (other than 1) is prime or not
#include <stdio.h>
int main(){
int num, flag=0; /*flag is used to take decision */
printf("Enter a number: ");
scanf("%d",&num);
int i;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
flag=1;
}
if(flag == 1)
printf("NOT PRIME");
else
printf("PRIME");
return 0;
}
Output:
No comments:
Post a Comment