W.A.P in C to generate prime number.
#include<stdio.h>
#include<conio.h>
void
main()
{
int
num,n,i=2;
clrscr();
printf("\n\t\t\t
PRIME NUMBERS\n");
printf("\n\nEnter
last no. till you want prime number:- ");
scanf("%d",&n);
printf("\nPrimes
no are:\n ");
for(num=1;num<=n;num++)
{
for(i=2;i<num;i++)
{
if(num%i==0)
break;
}
if(num==i)
{
printf("%-4d",num);
}
}
getch();
}
output:
PRIME
NUMBERS
Enter
last no. till you want prime number:- 100
Primes
no are:
2
3 5 7
11 13 17
19 23 29
31 37 41
43 47 53
59 61 67 71
73 79
83 89 97
Excellent explanation by admin
ReplyDeleteprogram for Print Prime numbers from 1 to n
Prime number program in C
ReplyDeleteThanks sir