C++入门经典-例3.18-使用for循环计算从1到10的累加

1:代码如下:

// 3.18.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
    int sum=0;
    int i;
    for(i=1;i<=10;i++)    //for循环语句
        sum+=i;
    cout << "数字1-10的和:" << sum << endl;
}
View Code

运行结果:

posted @ 2017-09-13 16:14  一串字符串  阅读(2108)  评论(0编辑  收藏  举报