0 of 1 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 1 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
27. (读入整数)请完善下面的程序,使得程序能够读入两个 int 范围内的整数,并将这两个整数分别输出,每行一个。
输入的整数之间和前后只会出现空格或者回车。输入数据保证合法。
例如:
输入:123 -789
输出:
123
-789
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <iostream> using namespace std; int readint() { int num = 0; // 存储读取到的整数 int negative = 0; // 负数标识 char c; c = cin.get(); // 存储当前读取到的字符 while ((c < '0' || c > '9') && c != '-') c = ① ; if (c == '-') negative = 1; else ② ; c = cin.get(); while ( ③ ) { ④ ; c=cin.get(); } if (negative == 1) ⑤ ; return num; } int main() { int a, b; a = readint(); b = readint(); cout << a << endl << b << endl; return 0; } |
填空位置 ①:
填空位置 ②:
填空位置 ③:
填空位置 ④:
填空位置 ⑤: