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++;
}
}
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: