美文网首页
[C++ Primer] 练习1.13

[C++ Primer] 练习1.13

作者: 和平北路 | 来源:发表于2017-02-17 13:57 被阅读0次
    #include <iostream>
    
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main() {
        int sum = 0;
        for (int i = 50; i <= 100; ++i) {
            sum += i;
        }
        cout << sum << endl;
    }
    
    #include <iostream>
    
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main() {
        for (int i = 10; i >= 0; --i) {
            cout << i << " ";
        }
        cout << endl;
    }
    
    #include <iostream>
    
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main() {
        int start = 0, end = 0, temp = 0;
        cin >> start >> end;
    
        if (start > end) {
            temp = start;
            start = end;
            end = temp;
        }
    
        for (int i = start; i <= end; ++i) {
            cout << i << " ";
        }
        cout << endl;
    }
    

    相关文章

      网友评论

          本文标题:[C++ Primer] 练习1.13

          本文链接:https://www.haomeiwen.com/subject/yftlwttx.html