1.while循环:
#include <iostream> using namespace std; int main() { int b = 1; int sum = 0 ; while (b<101) { sum += b; b++; } cout << "总数为:" << sum << endl; system("pause"); return 0; }
2.for循环
#include <iostream> using namespace std; int main() { int i, sum = 0; for (i = 1; i < 101; i++) { sum += i; } cout << "总数为:" << sum << endl; system("pause"); return 0; }

 

posted on 2022-08-14 18:05  wshidaboss  阅读(993)  评论(0编辑  收藏  举报