### Thread: Show prime numbers(use to be:help!)

1. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2003
Location
Philippines
Posts
2
Rep Power
0

#### help!

hello, i'm new !

the program is to make a program that will display all prime numbers.:D
2. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2003
Posts
138
Rep Power
15
Hi Jim,
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.

PHP Code:
``` #include <stdio.h> #include <stdlib.h> #include <math.h> int main(int argc, char** argv) {     int max,flag =0,i,j;     printf("\nEnter the maximum numbers u want prime for:");     scanf("%d",&max);          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;                 break;             }         }         if(flag == 0)         {             printf(" %d",i);                      }     }     printf("\n");     fflush(stdin);     getchar();     return 0; }  ```
Last edited by Raghuraman; July 31st, 2003 at 09:54 AM.
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Oct 2002
Location
Flint, MI
Posts
328
Rep Power
16

#### Re: help!

Originally posted by sigh
the program is to make a program that will display all prime numbers.:D
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.
4. 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.
5. #### 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".
6. No Profile Picture
gon
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Aug 2003
Location
house
Posts
2
Rep Power
0
oppps !
sorry i forgot to add, the range is from 2 to 150 .

thank for all of you who help me
thanks again
7. #### Re: Not only that...

Originally posted by mitakeet
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".
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 :-)
8. 2-150? Wow, that's a short range.

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
101
103
107
109
113
127
131
137
139
149

pseudo code:
Code:
```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