zoukankan      html  css  js  c++  java
  • for循环语句的简单列子

    求1到100的累加和

    #include<iostream>
    using namespace std;
    int main()
    {
       int a(0),i(1);
       for(;;)
       {
            a+=i++;
            if(i==101)
                break;
       }
        cout<<"a="<<a<<endl;
    }

    ——————————————————————————————————————

    同上

    #include<iostream>
    using namespace std;
    int main()
    {
       int a(0);
       for(int i=1;;)
        {a+=i++;
       if(i==101)
        break;
        }
        cout<<"a="<<a<<endl;
    }
    ————————————————————————————————————

    同上

    #include<iostream>
    using namespace std;
    int main()
    {
       int a(0);
       for(int i=1;i<=100;)
        a+=i++;
        cout<<"a="<<a<<endl;
    }
    —————————————————————————————————————

    同上

    #include<iostream>
    using namespace std;
    int main()
    {
       int a(0);
       for(int i=1;i<=100;a+=i++)
       {

       }
        cout<<"a="<<a<<endl;
    }
    ——————————————————————————————————————

    同上

    #include<iostream>
    using namespace std;
    int main()
    {
       int a(0),i(1);
       for(;i<=100;a+=i++)
       {

       }
        cout<<"a="<<a<<endl;
    }
    ——————————————————————————————————————

  • 相关阅读:
    IT系统
    大型云计算平台的搭建以及解决方案(超详细)(http://c.biancheng.net/view/3961.html)
    E
    Codeforces Round #694 (Div. 1) B. Strange Definition
    Codeforces Round #691 (Div. 2) D. Glass Half Spilled
    Educational Codeforces Round 100 (Rated for Div. 2) 1463D. Pairs
    (指针主席树简单介绍)第k小数
    11月刷题记录
    (补题)牛客国庆集训派对day4
    蓝桥杯前最后的挣扎(雾
  • 原文地址:https://www.cnblogs.com/ywj2013/p/3137932.html
Copyright © 2011-2022 走看看