+ 1
How can i make a C program finding prime numbers between input range using only while loop? (No for or other loops)
C language
3 Respuestas
+ 2
This should work
Anyway
for(i=min; i<max; i++)
{
...
}
and
i=min
while(i<max)
{
...
i++;
}
are basically the same
#include<stdio.h>
#include<math.h>
int main()
{
int i,j,k,a,b;
printf("insert range (min,max): ");
scanf("(%d,%d)",&a,&b);
i=a;
while(i<=b)
{
j=2;
while(j<=sqrt(i))
{
k=1;
if(i%j==0)
{
k=0;
break;
}
j++;
}
if(k)
printf("%d\n",i);
i++;
}
return 0;
}
+ 2
Minimum 2 loops
+ 1
Thank you so much lea