#include <stdio.h>
int
main(int argc, char **argv) {
int n, c, x;
printf("Enter a number\n");
scanf("%d", &n);
for ( c = n+1 ; ; c++ ) {
for (x = 2; x < c; x++) {
if ( c % x == 0 ) {
if (c == n){
printf("The next prime number is %d", c);
break;
}
}
}
}
return 0;
}
//your code properly indented
for ( c = n+1 ; ; c++ ) {
for (x = 2; x < c; x++) {
if ( c % x == 0 ) {
if (c == n){ //¿when this will be true?
printf("The next prime number is %d", c);
break;
}
}
}
}
Now read your code.
You start with c=n+1 but your condition is c==n
Then the break will just escape the inner loop, the outter is still an infinite loop
FInally, your "prime" definition is wrong, do it in paper first.
I'm so confused right nowwwwww.. going round n round in circles :'(
I don't really have a guard though... isn't it just infinite until I find the next prime?!?!