读入5个正整数并且显示它们。当程序读入的数据为负数时,程序立即终止。 **输入格式要求:"%d" 提示信息:"Please enter n:" **输出格式要求:"n = %d\n" "Program is over!\n"
时间: 2024-01-01 07:04:16 浏览: 94
C语言循环实现输入一批整数统计正负数个数
以下是代码实现:
```c
#include <stdio.h>
int main() {
int n;
printf("Please enter n: ");
scanf("%d", &n);
while (n >= 0) {
printf("n = %d\n", n);
printf("Please enter n: ");
scanf("%d", &n);
}
printf("Program is over!\n");
return 0;
}
```
运行结果示例:
```
Please enter n: 1
n = 1
Please enter n: 3
n = 3
Please enter n: 5
n = 5
Please enter n: -1
Program is over!
```
阅读全文