编程基本功——嵌套ifelse语句的妙用

一、问题

    对输入的成绩进行等级划分

二、分析

    使用if-else嵌套语句时必须注意else与if的配对正确

三、源码

   1: #include <stdio.h>
   2:  
   3: int main()
   4: {
   5:     int nScore;
   6:     printf("please input the score\n");
   7:     scanf("%d", &nScore);
   8:     if (nScore < 80)
   9:     {
  10:         if (nScore < 70)
  11:         {
  12:             if (nScore < 60)
  13:             {
  14:                 printf("E\n");
  15:             }
  16:             else
  17:             {
  18:                 printf("D\n");
  19:             }
  20:         }
  21:         else
  22:         {
  23:             printf("C\n");
  24:         }
  25:     }
  26:     else
  27:     {
  28:         if (nScore < 90)
  29:         {
  30:             printf("B\n");
  31:         }
  32:         else
  33:         {
  34:             printf("A\n");
  35:         }
  36:     }
  37:     getchar();
  38:     return 0;
  39: }
原文地址:https://www.cnblogs.com/steven_oyj/p/1742449.html