prime number print as per given range

#include<stdio.h>
int
main()
{
int i,j,flag,temp;
int beg,end;
scanf("%d %d",&beg,&end);
if(beg==1)
beg=2;
if(beg>end)
{
temp=beg;
beg=end;
end=temp;
}
for(i=beg;i<=end;i++)
{
flag=0;
for(j=2;j<i;j++)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("%d ",i);
}
return 0;
}

Comments

Popular posts from this blog

Basic calculator using C programming

Factorial of consecutively 5 numbers(input)

Square Root of a number without using math.h function