qfedu-basic-level/day7/d10.cpp

20 lines
349 B
C++
Raw Permalink Normal View History

2023-06-21 14:30:56 +08:00
#include <iostream>
using namespace std;
int main()
{
int i = 1, total1 = 0, total2 = 0;
for (; i <= 100; i++)
{
if (i % 2 == 0)
total1 += i;
else
total2 += i;
}
cout << "1~100的偶数和为: " << total1 << endl;
cout << "1~100的奇数和为: " << total2 << endl;
return 0;
}