题目:
用if条件语句,编写一个程序,要求从键盘上输入某哥学生的四科成绩,求出该学生的最高分和最低分
参考程序:
#include <stdio.h>
int main(int argc, const char * argv[]) {
//定义4个变量,接受四科成绩
int km1,km2,km3,km4;
km1=km2=km3=km4=0;
//提示学生输入成绩,并接收
printf("请依次输入四科成绩(并用逗号隔开):\n");
scanf("%d,%d,%d,%d",&km1,&km2,&km3,&km4);
if(km1>km2){
if(km1>km3){
if(km1>km4){
printf("最高分为km1=%d\n",km1);
}else{
printf("最高分为km4=%d\n",km4);
}
}else{
if (km3>km4) {
printf("最高分为km3=%d\n",km3);
}else {
printf("最高分为km4=%d\n",km4);
}
}
}
else{
if(km2>km3){
if(km2>km4){
printf("最高分为km2=%d\n",km2);
}else{
printf("最高分为km4=%d\n",km4);
}
}else{
if (km3>km4) {
printf("最高分为km3=%d\n",km3);
}else {
printf("最高分为km4=%d\n",km4);
}
}
}
if(km1<km2){
if(km1<km3){
if(km1<km4){
printf("最低分为km1=%d\n",km1);
}else{
printf("最低分为km4=%d\n",km4);
}
}else{
if (km3<km4) {
printf("最低分为km3=%d\n",km3);
}else {
printf("最低分为km4=%d\n",km4);
}
}
}
else{
if(km2<km3){
if(km2<km4){
printf("最低分为km2=%d\n",km2);
}else{
printf("最低分为km4=%d\n",km4);
}
}else{
if (km3<km4) {
printf("最低分为km3=%d\n",km3);
}else {
printf("最低分为km4=%d\n",km4);
}
}
}
return 0;
}
|
|