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;
}