c语言中循环控制语句 (do语句,限制用户输入数值的范围)

 

c语言中循环控制语句(do语句,限制用户输入数值的范围)

1、

#include <stdio.h>

int main(void)
{
    int i;
    do
    {
        puts("please input an integer! the range is 0-2!");
        printf("i = "); scanf("%d", &i);
    }
    while (i < 0 || i > 2);     ## 此句判断为非0,则继续执行循环体
    switch (i)
    {
        case 0: puts("you had choose stone!"); break;
        case 1: puts("you had choose scissors!"); break;
        case 2: puts("you had choose clothes!"); break;
    }
    return 0;
}

 

上一篇:新冠流行病期经历的病痛


下一篇:2021年江门市中考录取分数线(江门)