大一初学者求助
c语言吧
全部回复
仅看楼主
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
不少看不懂[惊哭]不过还是谢啦
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 9
[大拇指]
2013年09月22日 21点09分 4
level 5
没错啊,你是不是输入的时候逗号弄成中文逗号了,scanf()里不要逗号隔开啊!这是很不好的写法,直接用空格隔开
2013年09月22日 23点09分 5
恩恩,谢谢提醒!
2013年09月23日 04点09分
level 12
大一就这么快。、我们才学scanf
2013年09月22日 23点09分 6
专业要求,我的是数计专业
2013年09月23日 04点09分
level 12
那个大学??加个好友吧、、269258864
2013年09月22日 23点09分 7
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 5
大一求教,不懂符号意思,怎么写啊。 求大神小教几招[委屈]
2013年09月23日 01点09分 9
多编几个程序就会了,没事打书上的程序
2013年09月24日 16点09分
回复 天生废物二代 :哦,行。谢了,今天跟别的班去上课。多编几次程
2013年09月25日 00点09分
level 11
max=(a>b?a:b);
max=(max>c?max:c);
这个接8楼
2013年09月23日 04点09分 10
推荐www.fenby.com 自学c语言,3天学出大概
2013年09月23日 05点09分
回复 俯视627339815 :恩恩,谢了!
2013年09月23日 17点09分
level 7
你用的啥 编程软件
2013年09月23日 05点09分 11
C++2008
2013年09月23日 17点09分
level 9
我看没有问题啊,形参和实参我也搞不太清楚
2013年09月23日 07点09分 12
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 9
我自一周学到数据类型了,高中
2013年09月23日 23点09分 15
level 9
这是我书上的,你看下
2013年09月23日 23点09分 16
喔喔!谢啦谢啦!
2013年09月24日 16点09分
level 1
scanf("%d,%d,%d",&a,&b,&c),自己在运行后输入时也必须加上,隔开数字
2013年09月24日 14点09分 17
level 7
看见很多朋友 不是来帮忙的 至于来干嘛的 都懂的
2013年09月24日 15点09分 18
1