黑马程序员技术交流社区
标题:
if的作用域紊乱
[打印本页]
作者:
姚春林
时间:
2015-11-22 01:04
标题:
if的作用域紊乱
视频上if作用域紊乱这一点讲的有些模糊,谁能给解释解释?
作者:
junjunzhang
时间:
2015-12-11 02:39
/*
编写一个程序,要求从键盘上输入某个学生的四科成绩,求出该学生的最高分和最低分
*/
#include <stdio.h>
int main () {
int score1,score2,score3,score4;
printf ("请输入四科分数,用逗号进行分隔:\n");
scanf ("%d,%d,%d,%d",&score1,&score2,&score3,&score4);
if (score1 > score2) {
if (score3 > score4) {
if (score1 > score3 && score2 >score4){
printf ("最大值为:%d\n",score1);
printf ("最小值为:%d\n",score4);
} else {
printf ("最大值为:%d\n",score3);
printf ("最小值为:%d\n",score2);
}
} else {
if (score1 > score4 && score2 >score3) {
printf ("最大值为:%d\n",score1);
printf ("最小值为:%d\n",score3);
} else {
printf ("最大值为:%d\n",score4);
printf ("最小值为:%d\n",score2);
}
}
} else {
if (score3 > score4) {
if (score2 > score3 && score1 > score4) {
printf ("最大值为:%d\n",score2);
printf ("最小值为:%d\n",score4);
} else {
printf ("最大值为:%d\n",score3);
printf ("最小值为:%d\n",score1);
}
} else {
if (score2 > score4 && score1 > score3) {
printf ("最大值为:%d\n",score2);
printf ("最小值为:%d\n",score3);
} else {
printf ("最大值为:%d\n",score4);
printf ("最小值为:%d\n",score1);
}
}
}
return 0;
}
复制代码
看懂就差不多了
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2