while控制语句实现从1到10的求和功能

 1 #include "stdafx.h"
 2 
 3 #include<iostream>
 4 using namespace std;
 5 int main()
 6 {
 7 
 8     int sum = 0, n = 1;
 9 
10     while (n <= 10) {
11         sum = sum + n;
12         ++n;
13     }
14 
15     cout << sum << endl;
16 
17     system("pause");
18     return 0;
19 }

posted on 2018-07-21 15:25  mengtianwxs  阅读(2062)  评论(0)    收藏  举报

导航