# how to know prime numbers in 1 to 1000

Page 1 of 1

## 3 Replies - 25279 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=b880b7203bfc54ff6dabd202f219d3f4&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 parvathi.

• New D.I.C Head

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: 387
• Posts: 1,663
• 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

Was This Post Helpful? 0

### #3 spintronic

• D.I.C Head

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".
Was This Post Helpful? 0

### #4 janotte

• code > sword

Reputation: 991
• 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!

Please edit your posting (see the "EDIT" button in lower right).
( a ) Delete all your code.
( b ) Get a fresh copy of the code with formatting in place from your editor / IDE.
( c ) Paste the formatted code between code tags like this
( d ) Use the "Preview Post" button to check it's all good.
( e ) Use the "Submit Modified Post" button to finish the editing.
Was This Post Helpful? 0

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }