小编mak*_*ker的帖子

有没有办法用switch缩短if else语句?

我需要找到一种方法来使用switch缩短我的if-else语句。if-else语句很长,看起来真的很不专业,我希望有一种方法可以将它们缩短为几行,而不是像我现在看到的那样多行。

我尝试实现一个开关块,但是开关没有正确地按我希望的方式运行。

int numbers(int tal[]) {
int choice,a;
printf("\nWrite a specific number: ");
scanf("%d", &choice);
int b = 0;
for(a = 0 ;a < MAX ;a++){
    if(tal[a]== choice){
        b = 1;
        printf("\nExists in the sequence on this location: ");
        if(a <= 9)
        printf(" Row 1 och column %d\n",a +1);
        else if (a > 9 &&a <= 19)
        printf(" Row 2 och column %d\n", (a +1) - 10);
        else if (a > 19 &&a <= 29)
        printf(" Row 3 och column …
Run Code Online (Sandbox Code Playgroud)

c if-statement switch-statement

2
推荐指数
1
解决办法
58
查看次数

标签 统计

c ×1

if-statement ×1

switch-statement ×1