Write a C program to generate all the prime numbers between 1 and n, where n is a value supplied by the user.
Program Code:
#include<stdio.h>
void main()
{
int r=0,i,f,j,ctr;
printf("\nEnter the range of the numbers:");
scanf("%d",&r);
for(i=2;i<=r;i++)
{
f=0;
for(j=1;j<=i/2;j++)
{
if(i%j==0)
f=f+1;
}
if(f==1)
{
printf("\t%d",i);
ctr++;
}
}
}
Post A Comment:
0 comments: