how to know prime numbers in 1 to 1000

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

Page 1 of 1

3 Replies - 8361 Views - Last Post: 28 December 2009 - 03:59 AM Rate Topic: -----

#1 parvathi.  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • The Persian Coder
  • member icon

Reputation: 282
  • View blog
  • Posts: 1,456
  • 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 :P

[rules][/rules]

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

Was This Post Helpful? 0
  • +
  • -

#3 spintronic  Icon User is offline

  • D.I.C Head

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

Re: how to know prime numbers in 1 to 1000

Posted 28 December 2009 - 03:57 AM

View Postparvathi., 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  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • 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 :code:
( 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