我有一个小任务交给我,我对该做什么感到非常困惑。
官方简报如下:

"Using switch, create a program that reads an integer from the keyboard and,
indicate that the number is smaller than 1 and or smaller than 10, and or
smaller than 100, and or smaller than 1000."

我试着从输入"int num = scanf("%d\n", &num);"
然后像下面这样做
"case (num < 1 && <100): {

    printf("Excellent!!\n" );
    }"

但我运气不好。请有人指点我正确的方向。
谢谢,
编辑:
尝试过,但不知道如何才能让它打印得很好:
#include <stdio.h>
int main () {

int num;
scanf("%d\n", &num);

switch(num) {

case 1:
{
if(num < 1 && num < 10) {

    printf("Excellent!!\n" );
    }
}


}
}

最佳答案

#include <stdio.h>

int main(void){
    int num;
    int range = 0;

    printf("input num:\n");
    scanf("%d", &num);
    if(num < 1)
        range = -1;
    else {
        while(num /= 10){
            ++range;
        }
    }
    switch(range){
    case -1:
        puts("smaller than 1");
        break;
    case 0:
        puts("smaller than 10");
        break;
    case 1:
        puts("smaller than 100");
        break;
    case 2:
        puts("smaller than 1000");
        break;
    default:
        puts("More than 1000\n");
    }
    return 0;
}

08-17 18:30