c - 如何用0结束循环?

标签 c loops

我是 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/

相关文章:

c - 尝试访问结构中的指针时失败

c - 在 C 中没有库的输入和输出

c - 与互联网同步时间?

java - 如何编写计算数组众数的方法?

c - pic32 上的 TIMER 32 位不能使用中断

c++ - 在 Visual Studio 2010 中打印版权符号

python - 跨数据框迭代函数

java - While 循环用户输入

ios - 遍历字典键数组以检查 (Int) 键是否可用

python - 如何在Python中的另一个循环中正确编写一个for循环?