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; }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/280550.html