Program to check whether a number is prime of not.

#include <stdio.h>
#include <math.h>
#define MAX 25
main()
{
int i=2,count=0;
short isprime();
system("clear");
printf("The First 25 Prime No's r:\n");
while(count<MAX)
{
if(isprime(i))
{
printf("%d ",i);
count++;
}
i++;
}
printf("\n");
}

short isprime(int i)
{
int j;
short check=1;/* It says wether the No. is prime or not assume that its prime*/
for(j=2;j<=sqrt((double)i);j++)
if(!(i%j)){check=0; break;}/* If its divisible by any No. less then  */
return(check);               /* its sqrt then break & say not prime */
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s