# First 50 Prime Numbers

Page 1 of 1

## 1 Replies - 11122 Views - Last Post: 24 April 2007 - 10:24 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=27133&amp;s=b56d471019592f3001ffcb53c1701402&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ATXFG

Reputation: 0
• Posts: 15
• Joined: 19-April 07

# First 50 Prime Numbers

Posted 24 April 2007 - 09:35 AM

This code determines whether, it is a prime number or not, 1 for true, 0 for false, how would I print out the first 50 prime numbers. Start with a while loop, probably.

```#include<stdio.h>
#include<conio.h>
#include<assert.h>

int is_prime(int n);

void main(void)
{
int n=0;
clrscr();
printf("An integer ");
scanf("%d",&n);
assert(n > 1);
n=is_prime(n);
if (n==1)
printf("\nThe number is prime");
else
printf("\nThe number is NOT a prime");
getch();
}

int is_prime(int n)
{
int i;
for(i=2;i<n;i++){
if (n%i)	 continue;
else	 return 0;
}
return 1;
}

```

This post has been edited by ATXFG: 24 April 2007 - 09:37 AM

Is This A Good Question/Topic? 0

## Replies To: First 50 Prime Numbers

### #2 vasdueva

Reputation: 15
• Posts: 141
• Joined: 03-April 07

## Re: First 50 Prime Numbers

Posted 24 April 2007 - 10:24 AM

You could add a while loop yes.

while(numberOfPrimes <50)
{
//test for primes
numberToBeTested++;
if(primeFound)
{
numberOfPrimes++;
}
}