C-program to find the Series of Prime Numbers

#include<stdio.h>
 
int main()
{
	int n, i = 3, count, c;
 
	printf("Enter the number of prime numbers required\n");
	scanf("%d", &n);
 
	if (n >= 1)
	{
		printf("First %d prime numbers are :\n", n);
		printf("2\n");
	}
 
	for (count = 2; count <= n; )
	{
		for (c = 2; c <= i - 1; c++)
		{
			if (i%c == 0)
				break;
		}
		if (c == i)
		{
			printf("%d\n", i);
			count++;
		}
		i++;
	}
 
	return 0;
}

Capture.PNG
Output
 
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

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