July 31st, 2003, 05:35 AM
hello, i'm new !
can somebody please help in c program .
the program is to make a program that will display all prime numbers.:D
July 31st, 2003, 09:51 AM
This should not be difficult to program if you understood what a prime number is.
First a basic of what a prime number is , if you already dont know..
prime numbers are numbers that are divisible by 1 and itself.
int main(int argc, char** argv)
int max,flag =0,i,j;
printf("\nEnter the maximum numbers u want prime for:");
printf("The prime numbers from 1 to %d are : ",max);
for(i= 1; i <= max; i++)
flag = 0;
/*Division is just for square root of the value i
sufficient to check all the possible*/
for(j =2 ; j <= sqrt(i); j++)
if(i%j == 0)
flag = 1;
if(flag == 0)
Last edited by Raghuraman; July 31st, 2003 at 09:54 AM.
July 31st, 2003, 10:06 AM
This sounds suspiciously like your homework. Since we aren't here to do your homework for you, tell us where you're having the problem and we'll see what we can do.
Articles and commentary on web development
July 31st, 2003, 12:57 PM
Plus, your subject title is unacceptable. You can refer to the sticky thread at the top of this forum for more information on how to post a question.
July 31st, 2003, 03:41 PM
Not only that...
But what do you mean by 'all prime numbers'? There are an infinite number of them. If you want prime numbers bigger than a value that will fit in your computer's word (probably 32 bits) you need extra libraries (or work in FORTRAN).
Try googling on "Sieve of Eratosthenes".
August 1st, 2003, 03:24 AM
sorry i forgot to add, the range is from 2 to 150 .
thank for all of you who help me
August 1st, 2003, 08:52 AM
Re: Not only that...
FORTRAN has the same limitations on range of integers it can support as C or C++ (i.e. typically 16, 32, or 64 bits on most systems).
If you want bigger integers in C, C++, or FORTRAN (specifically FORTRAN 90 or later) you are normally looking at user defined types or data structures with associated support functions.
I also assume you made a little typo and meant Sieve of Erastothenes :-)
August 1st, 2003, 12:59 PM
2-150? Wow, that's a short range.
setup list of primes
for each number in range:
if number is evenly divisible by any number in list of primes, mark as non-prime
If prime, add to list
print list of primes
Last edited by dog135; August 1st, 2003 at 01:11 PM.