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

1:代码如下:

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

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

运行结果:

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