我是 C 语言新手,有一个基本程序,它要求用户输入一个数字,然后打印这个数字及其所在的范围,例如 1-49。
最佳答案
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int n;
do {
// Read the number into n
printf("Enter a number: ");
if (scanf("%d", &n) != 1) {
perror("scanf");
exit(EXIT_FAILURE);
}
// Check arbitrary condition
if (n >= 1 && n <= 49) {
printf("%d is in the range 1-49\n", n);
}
} while (n != 0);
return EXIT_SUCCESS;
}
关于c - 如何用0结束循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42183448/