level 3
要编写一个程序,求a,b,c三者的最大值,我是个编程小白,以前没有接触过,先编写以下:
#include<stdio.h>
int main()
{
int max(int x,int y);
int a,b,c,d,e;
scanf("%d,%d,%d",&a,&b,&c);
d=max(a,b);
e=max(c,d);
printf("max=%d\n",e);
return 0;
}
int max(int x,int y)
{
int z;
if(x>y)z=x;
else z=y;
return(z);
}
在试验时发现答案不符,求解惑,谢谢!
2013年09月22日 16点09分
1
level 5
#include "stdafx.h"
#include "stdio.h"
int max(int x,int y)
{
if(x>y)
return x;
else
return y;
}
int main(int argc, char* argv[])
{
int a,b,c,num;
scanf("%d,%d,%d",&a,&b,&c);
num=max(a,b);
num=max(num,c);
printf("The max number is:%d",num);
return 0;
}
输入的时候用逗号隔开
2013年09月22日 16点09分
2
不少看不懂
![[惊哭]](/static/emoticons/u60cau54ed.png)
不过还是谢啦
2013年09月23日 04点09分
这个????? #include <stdafx. h>
2013年09月23日 23点09分
为什么要include"stdafx.h"?
2013年09月24日 15点09分
回复 a443850741 :这个是vc++上的,没什么意思
2013年09月24日 16点09分
level 13
printf(“%d”,max(a,max(b,c)));你看如何
2013年09月22日 18点09分
3
是其他不变么?就改这个吗?
2013年09月23日 04点09分
回复 宇宙王孙仓空 :他这个更为简洁明了
2013年09月24日 14点09分
恩,很简洁!比我的好多了...
2013年09月24日 16点09分
level 5
没错啊,你是不是输入的时候逗号弄成中文逗号了,scanf()里不要逗号隔开啊!这是很不好的写法,直接用空格隔开
2013年09月22日 23点09分
5
恩恩,谢谢提醒!
2013年09月23日 04点09分
level 7
int fun(int a,int b,int c)
{
return (a>(b=b>c?b:c))?a:b;
}
应该可以!!!
2013年09月23日 00点09分
8
刚接触啊,那你可能没接触到三目运算符,和你这种思路是一样的!
2013年09月23日 00点09分
回复 不挂bg : 三目运算符?。。。。额。。晕了。。
2013年09月23日 04点09分
可读性差,没有意义
2013年09月23日 05点09分
level 11
max=(a>b?a:b);
max=(max>c?max:c);
这个接8楼
2013年09月23日 04点09分
10
回复 俯视627339815 :恩恩,谢了!
2013年09月23日 17点09分
level 8
a>b?(a>c?a:c):(b>c?b:c) 就行,不必那么麻烦!
2013年09月23日 12点09分
13
冒号表达式很好。现在比较大小我都用它了。
2013年09月23日 17点09分
那些问号冒号是什么意思?
2013年09月23日 17点09分
教初学者这种可读性差的代码就秀出你的优越了?
2013年09月24日 13点09分
level 1
scanf("%d,%d,%d",&a,&b,&c),自己在运行后输入时也必须加上,隔开数字
2013年09月24日 14点09分
17