| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2137 人关注过本帖
标题:自学C语言。。。自己编的各位看看,哪里错啦。
只看楼主 加入收藏
giordano
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2004-8-17
收藏
 问题点数:0 回复次数:30 
自学C语言。。。自己编的各位看看,哪里错啦。

int max(int a,int b); main() { int x,y,z; int max(int a,int b); printf("input tuo numbers:\n"); scanf("%d%d",&x,&y); z=max(x,y); printf("maxmun=%d",z); } int max(int a,int b) { if(a>b)return a;else return b;

if(a=b)return a+b;else return a-b;

}

这个那里错拉。。各位高手指点啊!!!!

搜索更多相关主题的帖子: C语言 自学 
2004-08-17 05:33
♂twincle
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2004-8-4
收藏
得分:0 
max里的第二个if中应该是a==b两个等号,而且你的if有大问题,第一个else中就包含了a=b的情况,而第二个else中也包括了第一个if的情况,这样相互包含就乱了。最后还有一点就是main里的最后一句中应该是maxnum,不是maxmun~~

/cgi-bin/load_pic?verify=DRR8NUHogwm6XhIZFfyT5w%3D%3D" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://photoimg1./cgi-bin/load_pic?verify=DRR8NUHogwm6XhIZFfyT5w%3D%3D');}" onmousewheel="return imgzoom(this);" alt="" />
2004-08-17 10:08
♂twincle
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2004-8-4
收藏
得分:0 
还有就是你的max函数在最前面已经声明了,在main里就不用再声明一遍了

/cgi-bin/load_pic?verify=DRR8NUHogwm6XhIZFfyT5w%3D%3D" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://photoimg1./cgi-bin/load_pic?verify=DRR8NUHogwm6XhIZFfyT5w%3D%3D');}" onmousewheel="return imgzoom(this);" alt="" />
2004-08-17 10:10
玩具兵
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2004-8-17
收藏
得分:0 
[原创]

我是新手,也来试一下。 #include <stdio.h> //declare function prototype int max(int a, int b); int main() { int x, y, z; printf("Please input two numbers:\n"); scanf("%d%d", &x, &y); int max(int x, int y); //谢谢艺楠的指点,这一名真是多余,删除。 z = max(x, y); printf("maxmum = %d", z); return 0; } int max(int a, int b) { if(a > = b) return a; else return b; /*下面的一句看不懂? if(a = b) return a + b; else return a - b; */ }

[此贴子已经被作者于2004-08-18 13:09:14编辑过]

2004-08-17 14:18
忆楠
Rank: 1
等 级:新手上路
帖 子:721
专家分:0
注 册:2004-7-5
收藏
得分:0 

我给你修改了一下 不知道可不可以 至于你说看不懂的地方我也不知道为什么 编译能通过 但是却解释不了。。。。。。。

#include <stdio.h>

int max(int a, int b);

int main() { int x, y, z; printf("Please input two numbers:\n"); scanf("%d%d", &x, &y);

z = max(x, y); printf("maxmum = %d", z);

return 0; }

int max(int a, int b) { if(a>=b) return a; else return b;

if(a = b) return a + b; else return a - b;

}


点 鼠 标 , 救 饥 民 http://www./
2004-08-17 18:58
hu_sir
Rank: 1
等 级:新手上路
帖 子:208
专家分:0
注 册:2004-4-29
收藏
得分:0 
if(a=b)return a+b;else return a-b;该语句没有作用
2004-08-18 18:57
silvermoon
Rank: 1
等 级:新手上路
帖 子:188
专家分:0
注 册:2004-8-20
收藏
得分:0 
if括号里面应该是判断语句判断相等用==而不是用赋值语句=

我是一棵菠菜~~菜菜菜菜菜~~~
2004-08-20 14:45
空前
Rank: 1
等 级:新手上路
帖 子:1146
专家分:0
注 册:2004-5-11
收藏
得分:0 

if(a=b)return a+b;else return a-b;这一句确实没有用,因为无论a或b是什么值,

if(a>=b) return a; else return b;

这一个条件语句已经够了,它总有一个返回值,所以下面的那个:

if(a = b) return a + b; else return a - b;

还没有执行就已经返回一个值给主函数了.(个人意见)


2004-08-22 23:42
xiyiwei
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2004-8-25
收藏
得分:0 

return 0;

这句有什么用?

2004-08-26 16:12
chennan
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2004-9-2
收藏
得分:0 

#include <stdio.h>

int max(int a,int b); int main() { int x,y,z; int max(int a,int b); printf("input tuo numbers:\n"); scanf("%d%d",&x,&y); z=max(x,y); printf("maxmun=%d",z);

return 0; }

int max(int a,int b) { if(a>b) return a;

else if(a=b) return a+b;

else if return a-b;

else return b;

}

2004-09-05 05:49
快速回复:自学C语言。。。自己编的各位看看,哪里错啦。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015745 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved