使用 scanf 函数进行多组输入的方法是在输入格式字符串中添加一个循环控制语句。例如,你可以使用 while 循环来不断读取输入,直到遇到终止条件为止。例如:
#include <stdio.h>
int main(void) {
int a, b;
while (scanf("%d%d", &a, &b) == 2) {
printf("a = %d, b = %d\n", a, b);
}
return 0;
}
在上面的代码中,scanf 函数会不断读取两个整数,直到输入失败为止。当输入失败时,scanf 函数会返回