I m trying to print the prime numbers using Sieve of Eratosthenes But, my output is 0 for all. please tell me where i m wrong.
Thanks for help
#include<stdio.h>
#include<conio.h>
int main()
{
int arr[100],i,j=1,val=0,mod,num=0,k,l;
for(i=0;i<100;i++)
{
arr[i]=j;
j++;
// printf("\n %d",arr[i]);
}
for(k=1;k<100;k++) // checking number and replacing appropriate with 0
{
val=arr[k];
if(val>0)
{
for(i=2;i<100;i++)
{
// printf("\n %d",i);
mod=arr[i]%val;
if(mod==0)
{
arr[i]=0;
}
else
{
continue;
}
}
}
else
{
continue;
}
}
for(num=0;num<100;num++) // taking output
{
if(arr[num]>0)
{
printf("\n %d",arr[num]);
}
else
{
continue;
}
}
getch();
}