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

运行结果:

原文地址:https://www.cnblogs.com/lovemi93/p/7515370.html