What's Here?
- Members: 244,265
- Replies: 693,099
- Topics: 113,153
- Snippets: 3,863
- Tutorials: 935
- Total Online: 1,171
- Members: 78
- Guests: 1,093
|
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: 14,365 |
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
|
|
|
Be Social
Programming
Web Development
Reference Sheets
Bye Bye Ads
Monthly Drawing
Top Contributors
Top 10 Kudos This Month
|