黑马程序员技术交流社区

标题: if的作用域紊乱 [打印本页]

作者: 姚春林    时间: 2015-11-22 01:04
标题: if的作用域紊乱
视频上if作用域紊乱这一点讲的有些模糊,谁能给解释解释?
作者: junjunzhang    时间: 2015-12-11 02:39
  1. /*
  2. 编写一个程序,要求从键盘上输入某个学生的四科成绩,求出该学生的最高分和最低分
  3. */
  4. #include <stdio.h>

  5. int main () {
  6.    
  7.     int score1,score2,score3,score4;
  8.    
  9.     printf ("请输入四科分数,用逗号进行分隔:\n");
  10.    
  11.     scanf ("%d,%d,%d,%d",&score1,&score2,&score3,&score4);
  12.    
  13.     if (score1 > score2) {
  14.    
  15.         if (score3 > score4) {
  16.         
  17.             if (score1 > score3 && score2 >score4){
  18.             
  19.                 printf ("最大值为:%d\n",score1);
  20.             
  21.                 printf ("最小值为:%d\n",score4);
  22.             
  23.             } else {
  24.                
  25.                 printf ("最大值为:%d\n",score3);
  26.             
  27.                 printf ("最小值为:%d\n",score2);
  28.             
  29.             }
  30.         
  31.         } else {
  32.         
  33.             if (score1 > score4 && score2 >score3) {
  34.             
  35.             printf ("最大值为:%d\n",score1);
  36.                
  37.                 printf ("最小值为:%d\n",score3);
  38.             
  39.             } else {
  40.                
  41.                 printf ("最大值为:%d\n",score4);
  42.                
  43.                 printf ("最小值为:%d\n",score2);
  44.             
  45.             }
  46.         
  47.         }
  48.    
  49.     } else {
  50.         
  51.         if (score3 > score4) {
  52.             
  53.             if (score2 > score3 && score1 > score4) {
  54.                
  55.                 printf ("最大值为:%d\n",score2);
  56.             
  57.                 printf ("最小值为:%d\n",score4);
  58.             
  59.             } else {
  60.                
  61.                 printf ("最大值为:%d\n",score3);
  62.                
  63.                 printf ("最小值为:%d\n",score1);
  64.             
  65.             }
  66.             
  67.         } else {
  68.             
  69.             if (score2 > score4 && score1 > score3) {
  70.                
  71.                 printf ("最大值为:%d\n",score2);
  72.                
  73.                 printf ("最小值为:%d\n",score3);
  74.             
  75.             } else {
  76.                
  77.                 printf ("最大值为:%d\n",score4);
  78.                
  79.                 printf ("最小值为:%d\n",score1);
  80.             
  81.             }
  82.             
  83.         }
  84.         
  85.     }
  86.    
  87.     return 0;
  88.         
  89.     }
复制代码

看懂就差不多了




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2