[C++ Primer] 练习1.13

2017-02-17  本文已影响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;
}
上一篇下一篇

猜你喜欢

热点阅读