80041 - 数位和统计(41~45题)
统计题目(材料题)
下面的程序输出1-1000中,各位数字之和等于指定值S的所有数,并且每输出10个满足条件的数就换一行再输出。请为每个空缺选择正确的代码。
01 #include <iostream>
02 using namespace std;
03 int main() {
04
05 int S, count = 0;
06 cin >> S;
07 for (int num = 1; num <= 1000; num++) {
08 int temp = num;
09 int digit_sum = 0;
10
11 while ( ① ) {
12 int digit = ② ;
13 digit_sum += digit;
14 temp = ③;
15 }
16
17 if ( ④ ) {
18 cout << num << " ";
19 count++;
20 if ( ⑤ ) {
21 cout << endl;
22 }
23 }
24 }
25
26 if (count == 0) {
27 cout << "No found" << endl;
28 } else {
29 cout << endl << count << endl;
30 }
31
32 return 0;
33 }

关注我们