/* Finding prime numbers in a limit and count them */
#include<stdio.h>
int main()
{
int l,u,n,i,r,flag,term=0;
printf("Enter lower limit:");
scanf("%d",&l);
printf("Enter upper limit:");
scanf("%d",&u);
printf("Prime number between %d and %d are:",l,u);
for(n=l;n<=u;n++)
{
flag=0;
for(i=2;i<n;i++)
{
r=n%i;
if(r==0)
{
flag=1;
break;
}
}
if (flag==0 &&n!=1)
{
printf("%d ",n);
term++;
}
}
printf("\nThere are total %d prime numbers exist between %d and %d\n",term,l,u);
return(0);
}
#include<stdio.h>
int main()
{
int l,u,n,i,r,flag,term=0;
printf("Enter lower limit:");
scanf("%d",&l);
printf("Enter upper limit:");
scanf("%d",&u);
printf("Prime number between %d and %d are:",l,u);
for(n=l;n<=u;n++)
{
flag=0;
for(i=2;i<n;i++)
{
r=n%i;
if(r==0)
{
flag=1;
break;
}
}
if (flag==0 &&n!=1)
{
printf("%d ",n);
term++;
}
}
printf("\nThere are total %d prime numbers exist between %d and %d\n",term,l,u);
return(0);
}
Comments
Post a Comment