#include <iostream> using namespace std; int main() { int n = 0; int ret = 0; //表达式的值,不断变化 int sum = 0; //最终结果 cin >> n; //循环遍历 for (int i = 1; i <= n; i++) { ret += i; sum += ret; } cout << sum; system("pause"); return 0; }
#include <iostream> using namespace std; int main() { int n = 0; int ret = 0; //表达式的值,不断变化 int sum = 0; //最终结果 cin >> n; //循环遍历 for (int i = 1; i <= n; i++) { ret += i; sum += ret; } cout << sum; system("pause"); return 0; }