What's Here?
- Members: 131,923
- Replies: 470,176
- Topics: 72,874
- Snippets: 2,538
- Tutorials: 665
- Total Online: 1,727
- Members: 62
- Guests: 1,665
Who's Online?
|
This program uses a simple method developed by Eratosthenes(Greek mathematician). Basically u select a number an strike of all its multiplies. then u go to the next number n so on till u reach the end. What ure left with r prime numbers.
|
Submitted By: Louisda16th
|
|
Rating:

|
|
Views: 10,376 |
Language: C
|
|
Last Modified: August 12, 2006 |
|
Instructions: compile, build n run |
Snippet
/* Finding Prime Numbers Using The Sieve Of Eratosthenes*/
#include<stdio.h>
void main()
{
int num[100], i, j;
for(i=0;i<=99;i++) /*Fill num with the first 100 numbers*/
num[i]=i+1;
for(i=1;i<=99;i++)
{
if(num[i]!=0)
{
for(j=(i+1);j<=99;j++)
{
if(num[j]!=0)
{
if((num[j]%num[i])==0) /*check if num[j]*/
num[j]=0; /*is a multiple of num[i]*/
/*if it is a multiple then set it to 0*/
}
}
}
}
for(i=0;i<=99;i++)
{
if(num[i]!=0) /*Print all non zero numbers (prime numbers)*/
}
}
Copy & Paste
|
|
|
Programming
Web Development
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|