# how to know prime numbers in 1 to 1000

Page 1 of 1

## 3 Replies - 12910 Views - Last Post: 28 December 2009 - 03:59 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=147263&amp;s=e84deacada2c38e8847cfabba4c69930&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 parvathi.

Reputation: 0
• Posts: 2
• Joined: 28-December 09

# how to know prime numbers in 1 to 1000

Posted 28 December 2009 - 02:59 AM

i want to knw simple logic to know the primenumbers between 1 to 1000

```#include <stdio.h>
main()
{
int n,i=1,j,c;
clrscr();
printf("Enter Number Of Terms
");
printf("Prime Numbers Are Follwing
");
scanf("%d",&n);
while(i<=n)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d	",i)
i++;
}
getch();
}
```

Is This A Good Question/Topic? 0

## Replies To: how to know prime numbers in 1 to 1000

### #2 Anarion

• The Persian Coder

Reputation: 378
• Posts: 1,651
• Joined: 16-May 09

## Re: how to know prime numbers in 1 to 1000

Posted 28 December 2009 - 03:03 AM

Why are you duplicating your topic? It's not being smart... you will not get any help unless you follow the rules

[rules][/rules]

This post has been edited by Anarion: 28 December 2009 - 03:07 AM

### #3 spintronic

Reputation: -32
• Posts: 94
• Joined: 25-December 09

## Re: how to know prime numbers in 1 to 1000

Posted 28 December 2009 - 03:57 AM

parvathi., on 28 Dec, 2009 - 01:59 AM, said:

#include <stdio.h>
main()
{
int n,i=1,j,c;
clrscr();
printf("Enter Number Of Terms
");
printf("Prime Numbers Are Follwing
");
scanf("%d",&n);
while(i<=n)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
printf("%d ",i)
i++;
}
getch();
}

http://en.wikipedia....unting_function

Look up "Sieve of Erastosthenes", "Legendre's Fomula", "Gaus" & "Riemann".

### #4 janotte

• code > sword

Reputation: 990
• Posts: 5,141
• Joined: 28-September 06

## Re: how to know prime numbers in 1 to 1000

Posted 28 December 2009 - 03:59 AM

\Welcome to DIC!