# prime no between 1 to 100 in c language

Page 1 of 1

## 6 Replies - 16206 Views - Last Post: 22 February 2009 - 07:52 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=88267&amp;s=51ff0a266a04af676a25035a97e4876e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 manoj_kr1976

Reputation: 0
• Posts: 8
• Joined: 22-February 09

# prime no between 1 to 100 in c language

Posted 22 February 2009 - 04:38 AM

how i display prime no between 1 to 100 ?
Is This A Good Question/Topic? 0

## Replies To: prime no between 1 to 100 in c language

### #2 DoubleFission

Reputation: 24
• Posts: 223
• Joined: 20-September 08

## Re: prime no between 1 to 100 in c language

Posted 22 February 2009 - 04:46 AM

Well first you have to work out how a single number is a prime number (If it has no factors except 1 and itself).

Then you just have a for loop which goes through 1 to 100, printing it out when done...

Simple

### #3 manoj_kr1976

Reputation: 0
• Posts: 8
• Joined: 22-February 09

## Re: prime no between 1 to 100 in c language

Posted 22 February 2009 - 04:57 AM

manoj_kr1976, on 22 Feb, 2009 - 03:38 AM, said:

how i display series of prime no between 1 to 100 in c language?

### #4 manoj_kr1976

Reputation: 0
• Posts: 8
• Joined: 22-February 09

## Re: prime no between 1 to 100 in c language

Posted 22 February 2009 - 05:52 AM

```main()
{
int x,y;
for (x=1;x<=100;x++)
{
for(y=2;y<x;y++)
{
if(x%y==0)
{
printf("%d",x);
}
}
}
getch();
}
```

EDIT: Added [ code ] tags

### #5 pdkharkar

• D.I.C Regular

Reputation: 65
• Posts: 345
• Joined: 19-January 09

## Re: prime no between 1 to 100 in c language

Posted 22 February 2009 - 06:29 AM

[quote name='manoj_kr1976' post='550052' date='22 Feb, 2009 - 05:09 AM']
[quote name='manoj_kr1976' post='550046' date='22 Feb, 2009 - 04:59 AM']
```main()
{
int x,y;
for(x=1;x<=100;x++)
{
for(y=2;y<x;y++)
{
if(x%y==0)
printf("%d",x);
}
}

```

thats is bro!!!

try if it is working, because I am not sure cause I haven't run it!!!
if the problem persists, plzzz let me know.
I'll try furthur..

This post has been edited by pdkharkar: 22 February 2009 - 06:31 AM

### #6 crazyjugglerdrummer

• GAME OVER. NERD WINS.

Reputation: 121
• Posts: 690
• Joined: 07-January 09

## Re: prime no between 1 to 100 in c language

Posted 22 February 2009 - 06:59 AM

Please don't double post you questions.

Here is a solution using the sieve of eratothenes.
```int main(int argc, char * const argv[])
{
const long maxnumber=10000000;

bool numbers[maxnumber];

for(long a=0; a<maxnumber; a++)
{
numbers[a]=true;
}

for(long x=2; x<maxnumber; x++)
{
if ( numbers[x] )
{

for (long y=2; y<maxnumber/x; y++)
{
numbers[y*x]=false;
}

}
}

for (long b=0; b<maxnumber; b++)
{
cout << numbers[b] << endl;
}
return 0;
}
```

I originally used vectors for infinite storage capacity.
Hope this helps!!

• Saucy!

Reputation: 6219
• Posts: 23,965
• Joined: 23-August 08

## Re: prime no between 1 to 100 in c language

Posted 22 February 2009 - 07:52 AM

Topics merged.