0

## 請問我該如何修改程式使其能判斷100和0? 謝謝

#include <stdio.h>

int main(void) {

``````int b,a;
printf("Enter a numerical grade: ");

scanf("%1d%1d", &a, &b);

switch (a){

case 1:
case 2:
case 3:
case 4:
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;

``````

}
return 0;

}

### 2 個回答

1

iT邦大神 1 級 ‧ 2020-10-02 21:28:10

#include <stdio.h>

int main(void) {

int b,a;
printf("Enter a numerical grade: ");

scanf("%d %d", &a, &b);

switch (a){

``````case 0:
printf("case 0");
break;
case 1:
case 2:
case 3:
case 4:
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 100:
printf("Case 100");
break;
``````

}
return 0;

}

ktro12 iT邦新手 5 級 ‧ 2020-10-03 09:39:54 檢舉

ktro12 iT邦新手 5 級 ‧ 2020-10-03 10:04:40 檢舉

ktro12 iT邦新手 5 級 ‧ 2020-10-03 10:05:13 檢舉

ktro12 iT邦新手 5 級 ‧ 2020-10-03 22:05:46 檢舉

ktro12 iT邦新手 5 級 ‧ 2020-10-03 22:35:43 檢舉

100到90 89到80 79到70 69到60

ktro12 iT邦新手 5 級 ‧ 2020-10-03 22:36:23 檢舉

#include <stdio.h>

int main(void) {

int b,a;
printf("Enter a numerical grade: ");

scanf("%d %d", &a, &b);

switch (a) {
case 0 ... 59:
break;
case 60 ... 69:
break;
case 70 ... 79:
break;
case 80 ... 89:
break;
case 90 ... 100:
break;
}
return 0;

}

ktro12 iT邦新手 5 級 ‧ 2020-10-03 23:31:01 檢舉

ktro12 iT邦新手 5 級 ‧ 2020-10-04 00:02:34 檢舉

Input Data:

Except:

# Enter a numerical grade: Letter grade: B

Actual result:

Enter a numerical grade:

#include <stdio.h>

int main(void) {

int b,a;
printf("Enter a numerical grade: ");

scanf("%d", &a);

switch (a) {
case 0 ... 59:
break;
case 60 ... 69:
break;
case 70 ... 79:
break;
case 80 ... 89:
break;
case 90 ... 100:
break;
}
return 0;

}

ktro12 iT邦新手 5 級 ‧ 2020-10-04 00:14:04 檢舉

0

iT邦大師 1 級 ‧ 2020-10-03 00:29:59

%d直接判斷整個數字不好嗎?

ktro12 iT邦新手 5 級 ‧ 2020-10-03 09:08:04 檢舉

ktro12 iT邦新手 5 級 ‧ 2020-10-03 22:05:59 檢舉

ktro12 iT邦新手 5 級 ‧ 2020-10-03 22:37:26 檢舉