A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 姚春林 中级黑马   /  2015-11-22 01:04  /  783 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

视频上if作用域紊乱这一点讲的有些模糊,谁能给解释解释?

1 个回复

倒序浏览
  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.     }
复制代码

看懂就差不多了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马