(1)用IF嵌套:
#include <iostream> using namespace std; int main() { int i=100; int minNum; while(i>0) { if(i%3==2) { if(i%5==3) { if(i%7==2) { minNum=i; } } } i--; } cout<<minNum<<endl; return 0; }
(2)用FOR和IF语句综合:
#include <iostream> using namespace std; int main() { int i=100; int x; for(x=1;x<100;x++) { if((x%3==2)&&(x%5==3)&&(x%7==2)) cout<<x<<endl; } return 0; }