prog5_03.cpp

来自「一本语言类编程书籍」· C++ 代码 · 共 23 行

CPP
23
字号
// Program 5.3 Using a for loop
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main() {
  int sum = 0;                        // Accumulates the sum of integers
  int count = 0;                      // The number to sum

  cout << "How many integers do you want to sum? ";
  cin >> count;

  for(int i = 1 ; i <= count ; i++)
    sum += i;

  cout << endl
       << "The sum of the integers from 1 to " << count 
       << " is " << sum << endl;

  return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?