1.用break语句
#includeint main() { int x; for(x=1;;x++) { if(x%5==1&&x%6==5&&x%7==4&&x%11==10) { printf("x=%dn",x); break; } } return 0; }
2.用标志变量flag
#includeint main() { int x; int found=0; for(x=1;!found;x++) { if(x%5==1&&x%6==5&&x%7==4&&x%11==10) { printf("x=%dn",x); found=1; } } return 0; }
3.想找到给定数量的解的时候(以求出五个解为例)
#includeint main() { int x; int found=0; for(x=1;found<5;x++) { if(x%5==1&&x%6==5&&x%7==4&&x%11==10) { printf("x=%dn",x); found++; } } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)