Monday, July 27, 2009

Programe to print prime numbers from 1 to 500 in C language?

Programe to print prime numbers from 1 to 500 in C language

Programe to print prime numbers from 1 to 500 in C language?
It is my while loop program:


Code:


--------------------------------------...


#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


void main()


{


int count,i=1;


int a;


clrscr();


while(i%26lt;=500)


{


count=0;


a=1;


while(a%26lt;=i)


{


if(i%a==0)


count++;


a++;


}


if(count==2)


printf("%d\t",i);


i++;


}


getch();


}
Reply:I'm not sure about C, but my brother made one in C++.
Reply:Here is the algo:


*Start from creating ur array[MAX] = {2,3};


*Add 2 to previous(last number). See if this is divisible by all the primes less than that number/2.


*Repeat until that number reaches 500.

brenda song

No comments:

Post a Comment