Chinaunix首页 | 论坛 | 博客

分类: 信息化

2014-11-26 20:58:27

#include

int main()

//定义5个变量,分别为数学,语文,物理,化学.
     float  math,chinese,physics,chemistry,zongshu;
    //数学的成绩为100,语文的成绩为99,物理的成绩为98,化学的成绩为97。
    int select;            //定义变量为选择。
    math= 100;


   chinese     =  99;


   physics     =  98;


   chemistry   =  97;


    zongshu     =  394;
    scanf("%d",&select );
   //如果select=1,打印数学成绩是100,结束程序。
   if(select==1)
  {
   printf("math is  %.2f\n",math);
   return 0;
  }
    // 如果select=2,打印成绩是语文99,结束程序。
    else if(select==2)
   {
   printf("chinese is  %.2f\n",chinese);
   return 0;
  }
  // 如果select=3,打印成绩是物理98,结束程序。
  else if(select==3)
  {
  printf("physics is  %.2f\n",physics);
  return 0;
  }
   // 如果select=4,打印成绩是物理98,结束程序。
    else if(select==4)
  {
        printf("chemistry is  %.2f\n",chemistry);
   return 0;
   }
   //如果select=其他,那么结果必须是总分 394,最后结束程序。
  else
  {
        printf("zongshu is  %3.2f\n",zongshu);
        return 0;
    }
   return 0;
}
如图:
数学:

语文:


物理:

化学:

总成绩:


阅读(1769) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~