C programming
int main()
{
int num,i,count,n;
printf("Enter the range :\n ");
scanf("%d",&n);
printf("Prime numbers between 1 to %d are :\n ",n);
for(num = 1;num<=n;num++)
{
count = 0;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
count++;
break;
}
}
if(count==0 && num!= 1)
printf("%d ",num);
}
return 0;
}
Try it Yourself ➠
Prime numbers between "1 to n" in C
26 July
0
Write a program (WAP) in C to print Prime numbers between "1 to n".
#include<stdio.h>int main()
{
int num,i,count,n;
printf("Enter the range :\n ");
scanf("%d",&n);
printf("Prime numbers between 1 to %d are :\n ",n);
for(num = 1;num<=n;num++)
{
count = 0;
for(i=2;i<=num/2;i++)
{
if(num%i==0)
{
count++;
break;
}
}
if(count==0 && num!= 1)
printf("%d ",num);
}
return 0;
}
Must Read :-
Previous article
Next article
Leave Comments
Post a Comment