谭浩强C程序设计5例子1.3是不是错了啊,题目是求3个数中较大者,可运行了那段程序看像是比较两个数的大小

[复制链接]
查看11 | 回复2 | 2010-12-26 16:48:40 | 显示全部楼层 |阅读模式
原程序如下:
#include "stdio.h"
void main()
{int max(int x ,int y);
int a,b,c;
scanf("%d,%d",&a,&b);
c=max(a,b);

printf("max=%d\n",c);

getch();
}
int max(int x,int y)
{int z;
if(x>y) z=x;
else z=y;
return(z);
}
谢谢
没有抄错,原书上就是这样写的,原书名为《C程序设计(第三版)谭浩强著》05年7月三版

回复

使用道具 举报

千问 | 2010-12-26 16:48:40 | 显示全部楼层
是作为比较两个数大小的代码还可以作为参考 变成比较3个数大小的代码,如下:#include "stdio.h"void main(){int max(int x ,int y,int z);int a,b,c,t;scanf("%d%d%d",&a,&b,&c);t=max(a,b,c);
printf("max=%d\n",t);
getch();}int max(int x,int y,int z){int temp;if(x>y) temp=x;else temp=y;if(z>temp) temp=z;return(temp);}int max(int x,
回复

使用道具 举报

千问 | 2010-12-26 16:48:40 | 显示全部楼层
#include #include int Max(int a,int b,int c){ int max = a;if( max < b){
max = b;}if( max < c){
max = c;}return max;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行