Advertisement
Maplewing

9/5 C: if-else if-else

Sep 5th, 2015
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.     int score;
  5.     scanf("%d", &score);
  6.    
  7.     /*
  8.         (X) 90 <= score <= 100
  9.             score = 95:  90 <= 95 <= 100
  10.                       =>    1     <= 100
  11.                       => 1
  12.             score = 89:  90 <= 89 <= 100
  13.                       =>    0     <= 100
  14.                       => 1
  15.     */
  16.    
  17.     if( (score >= 90) && (score <= 100) ){
  18.         printf("A+");
  19.     }
  20.     else if( score >= 85 && score <= 89 ){
  21.         printf("A");
  22.     }
  23.     else if( score >= 80 && score <= 84 ){
  24.         printf("A-");
  25.     }
  26.     // ........
  27.     /*
  28.         =:  score =  100 => 100
  29.        ==:  score == 100 => 等於   : 1
  30.                             不等於 : 0
  31.     */
  32.     else if( score == 0 ){
  33.         printf("X");
  34.     }
  35.    
  36.    
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement