Sieve Of Erasthothanese method to generate prime numbers - C/C++

A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called acomposite number.

Check best and different way to find prime numbers in C program. This method is also known as Sieve Of Erasthothanese method to generate prime numbers

Program Description:
Step 1: First the array is filled from 1 to 100.
Step 2: Then the array is Printed
Step 3: Then starting from number 2 and ignoring the number 1 all the
multiples of 2 are set to zero.
Step 4: Then this procedure is repeated for all numbersi.e from multiples of
3 upto 100.
Step 5: Finally the prime numbers are printed



#include
#include
#define n 100
int main()
{
 int num[n], i, j, k, inc, p = 1;
 int u;
 clrscr();
 for (i = 0; i <= n - 1; i++)
 {                   //to fill the array
  num[i] = i + 1;
 }
 printf("The numbers from 1 to 100 are:\n");
 for (i = 0; i10*p)   /*if value of element is greater than any multiple of 10
       then it gets printed in next line*/
 {
  printf("\n");
  p++;
 }
 printf("%5d", num[i]);
}
p = 1;              //re-initialising the value of p
for (i = 1; i10*p)
{
 p++;
 printf("\n");
}
if (num[i] != 0 && num[i] != 1)
{
 printf("%d\t", num[i]);
}
  }
  getch();
  return 0;
}
 
 
 

Post a Comment