Write a C program to print prime number up to a given range.

PROGRAM: Write a C program to print prime number up to a given range.
#include<stdio.h>
main()
{
int num,i,count=0,j;
printf("Enter a number \n");
scanf("%d",&num);
printf("The Prime numbers upto %d are\n",num);
for(i=1;i<=num;i++)
{
count=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
{
count++;
}
}
if(count==2)
{
printf("%d\n",i);
}
}
}
OUTPUT:-
Enter a number
30
The Prime numbers upto 30 are
2
3
5
7
11
13
17
19
23
29

Post a Comment

0 Comments