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

  • 相关阅读:
    第194场周赛
    刷leetcode的心得
    91. Decode Ways
    23. Merge k Sorted Lists
    19. Remove Nth Node From End of List
    21. Merge Two Sorted Lists
    222. Count Complete Tree Nodes
    958. Check Completeness of a Binary Tree
    课程学习总结报告
    结合中断上下文切换和进程上下文切换分析Linux内核一般执行过程
  • 原文地址:https://www.cnblogs.com/ywj2013/p/3137932.html
Copyright © 2011-2022 走看看