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

1:代码如下:

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

#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
    int sum=0,i=1;
    while(i<=10)
    {
        sum=sum+i;
        i++;
    }
    cout << "数字1-10之和 :" << sum << endl;
}
View Code

运行结果:

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