C Program- To check if no. is prime or not

Posted: January 19, 2012 in Lab 2
#include<stdio.h>
void isprime(int *);
void isprime(int *n)
{
	int i,f;
	if(*n<2)
		printf("Not Prime");
	else
	{
	for(i=2;i<(*n/2);i++)
	{
		if(*n%i==0)
		{
			f=1;
			break;
		}
	}
	if(f==1)
		printf("Not Prime");
	else
		printf("Prime");
	}
} 
int main()
{
	int n;
	printf("Enter the no.\n");
	scanf("%d",&n);
	isprime(&n);
	return 0;
}
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