9.write a C Program to generate all the prime numbers between 1 to n where n is value supplied by the user


Program to generate all the prime numbers between 1 to n  where n is value supplied by the user

Source Code:

#include<stdio.h>
int main()

{
int i,j,count=0,n;
printf("enter the value of upper limit: \n");
scanf("%d",&n);
printf("enter the value between 1 to %d: \n",n);

for(j=2;j<=n;j++)
{
for(i=1;i<=j;i++)
{
if(j%i==0)
count++;
}
if(count==2)
printf("%d\n",j);
count=0;
}
}

OutPut:

enter the value of upper limit:
25
enter the value between 1 to 25:
2
3
5
7
11
13
17
19
23


No comments:

Post a Comment