+ 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

16th Aug 2019, 7:49 PM
Aaditya Nair
Aaditya Nair - avatar
3 odpowiedzi
+ 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; }
17th Aug 2019, 12:38 AM
Lea
+ 2
Minimum 2 loops
16th Aug 2019, 8:17 PM
Marina Vasilyova
Marina Vasilyova - avatar
+ 1
Thank you so much lea
17th Aug 2019, 3:33 AM
Aaditya Nair
Aaditya Nair - avatar