‘C’ function to check if a number is prime.
C File =>
/* Write a ‘C’ function to check if a number is prime. Use this function to
display all prime numbers between 100 and 500. */
#include<stdio.h>
int main()
{
int i;
// function to check if number is prime
int isprime(int n)
{
int flag=1,i;
for(i=2;i<n-1;i++)
{
if(n%i==0)
{
flag=0;
break;
}
}
return flag;
}
printf("\n Prime numbers between 100 and 500 :\n");
for(i=100;i<500;i++)
{
if(isprime(i)==1)
printf("%d\t",i);
}
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.