首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

求问,多谢

2013-03-25 
求问,谢谢啊本帖最后由 renren_renren 于 2013-03-11 11:30:30 编辑#include stdio.hconst int N3void

求问,谢谢啊
本帖最后由 renren_renren 于 2013-03-11 11:30:30 编辑 #include <stdio.h>
const int N=3;
void main()
{
char name[10];
int age;
char sex;
float maths,english,computer,maxscore;
double average;
printf("please enter your name,age and sex:");
scanf("%s%d%c",&name,&age,&sex);
printf("please enter your scores(maths,english and computer):");
scanf("%f%f%f:",&maths,&english,&computer);
maxscore=maths;
if (english>maxscore)
   maxscore=english;
if(computer>maxscore)
   maxscore=computer;
average=(maths+english+computer)/N;
(maths>=90&&english>=90&&computer>=90)?printf("you are good!\n"):printf("you should study hard!\n"),
printf("name=%s,age=%d,sex=%c\nmaths=%f,englishi=%f,maxscore=%f,average=%f\n",name,age,sex,maths,english,computer,maxscore,average);
}

红逗号在此处为什么会用啊
[解决办法]
你说的逗号是逗号运算符,它的优先级最低。因此整个语句是先由问号运算符打印出,you are good!或者you should study hard!然后打印成绩。
[解决办法]
(maths>=90&&english>=90&&computer>=90)?printf("you are good!\n"):printf("you should study hard!\n")
, printf("name=%s,age=%d,sex=%c\nmaths=%f,englishi=%f,maxscore=%f,average=%f\n",name,age,sex,maths,english,computer,maxscore,average);

逗号是逗号运算符

热点排行