Aim :- Write a C program to print first n prime numbers.
Prime number logic : a number is prime if it is divisible only by one and itself. Remember two is the only even and the smallest prime number. First few prime numbers are 2, 3, 5, 7, 11, 13, 17, ....
C Program Code :
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i = 3, p, c;
clrscr();
printf("\nEnter The Number : ");
scanf("%d", &n);
if(n>=1)
{
printf("\nFirst %d Prime Numbers : \n", n);
printf("2 \n");
}
for(p = 2; p <= n; i++)
{
for(c = 2; c < i; c++)
{
if(i%c == 0)
break;
}
if(c == i)
{
printf("%d\n", i);
p++;
}
}
getch();
}
Output :
1 Comments
For me the objective was very clear from the beginning; I started link Lebois & Co out of passion with the intention to grow it into a link successful business meaning that I am still just as link passionate about watches as before.
ReplyDelete