• 最小正整数


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

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

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

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

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

    return 1;
    }

    #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;
    }

    最小正整数(续)    加速
    #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");   

    return 0;
    }

  • 相关阅读:
    产品经理必备工具之一:Axure产品原型设计
    解决UserDefault读取慢的问题
    MAC常用快捷键
    asi网络请求中遇到的一些问题的解决
    oc运行时runtime
    图片拉伸,气泡式
    ios nil、NULL和NSNull 的使用
    错误:linker command failed with exit code 1 (use v to see invocation)
    ios url 编码和解码
    SQL重置数据表id
  • 原文地址:https://www.cnblogs.com/wc1903036673/p/3870559.html
Copyright © 2020-2023  润新知