关于C语言程序的简单问题

来源:百度知道 编辑:UC知道 时间:2024/05/18 05:31:27
我编了一个C语言函数计算三个数中的最大值 和相应的输入和输出 但是不论我怎么排错总是有错 就是你不论输入什么数返回的总是我输入的第三个数 根本达不到目的 程序是这样的 那位大侠帮忙解决一下 小弟感激不尽。/* Note:Your choice is C IDE */
#include "stdio.h"
main()
{
int x,y,z,d;

printf("input x\n");
scanf("%d",&x);
printf("input y\n");
scanf("%d",&y);
printf("input z\n");
scanf("%d",&z);
d=max(x,y,z);
printf("the max is %d",d);
}

int max(int a,int b,int c)

{ int temp;
if (b<c) temp=b;b=c;c=temp;
if (a<b) temp=a;a=b;b=temp;

return(a);
}

在主函数之前先声明max函数.
int max(int a,int b,int c);
再把max函数改成这样就行了.
{ int temp;
if (b<c)

temp=b;b=c;c=temp;

if (a<b)

temp=a;a=b;b=temp;

return(a);
}

1 max 函数没有先声明就使用
2 if后超过一句要执行的要加大括号
if (b<c) {temp=b;b=c;c=temp;}
if (a<b) {temp=a;a=b;b=temp;}
最基本的语法 要多看

你怎么调用函数之前不声明阿……
而且下面的函数也有点问题哟~
#include "stdio.h"
void main()
{
int max(int a,int b,int c);
int x,y,z,d;
printf("input x\n");
scanf("%d",&x);
printf("input y\n");
scanf("%d",&y);
printf("input z\n");
scanf("%d",&z);
d=max(x,y,z);
printf("the max is %d\n",d);
}
int max(int a,int b,int c)
{ int temp;
if (a<b)temp=b;
if (b<c)temp=c;
else if(c<a) temp=a;
return(temp);
}
哦呵呵~

下面这程序我试了可以