/* A program to test whether a given number is prime or not */
#include <stdio.h>
int main()
{
int a,i,rem,flag=0;
printf("enter a number:");
scanf("%d",&a);
for(i=2;i<a/2;i++)
{
rem=a%i;
if(rem==0)
{
printf("%d is not prime",a);
flag=1;
break;
}
else
flag=0;
}
if (flag==0)
printf("%d is prime",a);
return 0;
}
#include <stdio.h>
int main()
{
int a,i,rem,flag=0;
printf("enter a number:");
scanf("%d",&a);
for(i=2;i<a/2;i++)
{
rem=a%i;
if(rem==0)
{
printf("%d is not prime",a);
flag=1;
break;
}
else
flag=0;
}
if (flag==0)
printf("%d is prime",a);
return 0;
}
No comments:
Post a Comment