clanguage07@gmail.com

clanguage07@gmail.com

Saturday, June 16, 2012

Write a C program to generate all the prime numbers between 1 and n, where n is a value supplied by the user.

#include <stdio.h>
void main()
{
int no,counter,counter1,check;
clrscr();
printf("<-----------------------PRIME NO. SERIES------------------------>");
printf("\n\n\n\t\t\tINPUT THE VALUE OF N: ");
scanf("%d",&no);
printf("\n\nTHE PRIME NO. SERIES B/W 1 TO %d : \n\n",no);
for(counter = 1; counter <= no; counter++)
{
check = 0;
//THIS LOOP WILL CHECK A NO TO BE PRIME NO. OR NOT.
for(counter1 = counter-1; counter1 > 1 ; counter1--)
if(counter%counter1 == 0)
{
check++; // INCREMENT CHECK IF NO. IS NOT A PRIME NO.
break;
}
if(check == 0)
printf("%d\t",counter);
}
getch();
}

No comments:

Post a Comment

GET MORE INFORMATION

http://ads.qadservice.com/t?id=c2168e05-8974-4816-872a-91936ff7379d&size=1024x768&drct=true