最小正整数

有一个整数,除5余三、除3余二、除2余1,            求知足条件的最小正整数。 ios

 

 

 

 

 

那么while(1)
其中1表明一个常量表达式,他永远不会等于0。
因此,循环会一直执行下去。
除非你设置break等相似的跳出循环语句循环 才会停止

 

#include <iostream>
using namespace std;
int main( )
{     int x=1;
      while(1)
      {
spa

                 if(x%5==3 && x%3==2 && x%2==1 )
                                                                         {    x++;    break;}
blog

}
       cout<<x<<endl;  
       system("pause"); 
io

return 1;
}
class

 

 

 

 

#include <iostream>
using namespace std;
int main( )
{     int x=1;
      while(1)
      {if(x%5==3 && x%3==2 && x%2==1 )
          { break;}
    x++;
    }
       cout<<x<<endl;  
       system("pause"); return 1;
}
stream

 

 

 

 

 

 

最小正整数(续)    加速
#include <iostream>
using namespace std;
int main( )
{    
循环

int x=3;
      while(1)
       { 
            if(x%3==2 && x%2==1)               break;
                                    x+=5;
        }
       cout<<x<<endl;
       system("pause");   
im

return 0;
}
db

相关文章
相关标签/搜索