猿问

下面是我的一个程序 ,但是我不明白那里错了 请高手指教一下!!

#include<stdio.h>
int max(int a,int b,int c);
{
max=a;
if(max<b)
max=b;
if(max<c)
max=c;
return(max);
}
void main()
{
int a,b,c,max;
printf("please input%d\n")
scanf("%d,%d,%d",&a,&b,&c);
max=max(a,b,c)
printf("the max is%d\n",max);
}

BIG阳
浏览 199回答 2
2回答

阿波罗的战车

1、变量名不要和类名重复...把程序中的max(除了max(a,b,c))换成其他名字(比如z)就可以了;2、max函数中注意else的情况!!会有没有完全包含可能的错误。程序如下:#include<stdio.h>&nbsp;int max(int a,int b,int c){int z;if(a<b) z=b;else z=a;if(z<c) z=c;else z=z;return z;}&nbsp;void main(){int a,b,c,m;printf("please input%d\n");scanf("%d,%d,%d",&a,&b,&c);m=max(a,b,c);printf("the max is%d\n",m);&nbsp;}&nbsp;

波斯汪

1: #include<stdio.h>&nbsp;2: int max(int a,int b,int c);&nbsp;3: {&nbsp;4: max=a;&nbsp;5: if(max<b)&nbsp;6: max=b;&nbsp;7: if(max<c)&nbsp;8: max=c;&nbsp;9: return(max);&nbsp;10: }&nbsp;11: void main()&nbsp;12: {&nbsp;13: int a,b,c,max;&nbsp;14: printf("please input%d\n")&nbsp;15: scanf("%d,%d,%d",&a,&b,&c);&nbsp;16: max=max(a,b,c)&nbsp;17: printf("the max is%d\n",max);&nbsp;18: }整个程序在逻辑上没什么问题,只是在语句书写、变量的定义和该用什么变量名等细节方面有些问题。首先,语句书写,第14、16句末缺少“;”其次,1、在max()函数体中,可以用函数名max作为局部变量,但也要先给予定义,即第3句后面添加一句 int max;2、第13、16句,变量max不能和函数max()同名,建议将变量max改名,如:13: int a,b,c,mx;16: mx=max(a,b,c);17: pintf("the max is %d\n",mx);3、可以直接在第17句中调用max(),这样可以省去第16句:17: printf("the max is %d\n",max(a,b,c));第三,第14句printf("please input %d\n");中含有%d,但是后面没有相应的输出数据,那么%d的位置就会显示内存中任意一个单元的值了。如果本意想显示字符“%”,应该用连续两个“%”表示,写成:printf("please input %%d\n");但是建议改成这样更明了:printf("please input three numbers , delimited with \",\"\n");意思是:请输入3个数,用“,”分隔整个程序修改如下:# include <stdio.h>int max(int a,int b,int c){ int max;max=a;if(max<b)max=b;if(max<c)max=c;return(max);}void main(){int a,b,c,mx;printf("please input %%d\n");scanf("%d,%d,%d",&a,&b,&c);mx=max(a,b,c);printf("the max is %d\n",mx);}或者:# include <stdio.h>int max(int a,int b,int c){ int max;max=a;if(max<b)max=b;if(max<c)max=c;return(max);}void main(){int a,b,c;printf("please input three numbers , delimited with \",\"\n");scanf("%d,%d,%d",&a,&b,&c);printf("the max is %d\n",max(a,b,c));}小伙子,这样的解答满意吗?&nbsp;
随时随地看视频慕课网APP
我要回答