Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

输出三个数中的最大值,程序出现错误!

代码

/****************************************************

    Copyright:Tan Haoqiang

    Author:Huang Zihan

    Date:2020-12-21

    Description:Output the largest one from a,b and c

  **************************************************/ 

#include <stdio.h>

int main()
{
   int a,b,c,m;
   int max(int x,int y,int z);
   scanf("%d,%d,%d
",&a,&b,&c);
   m=max(a,b,c);
   printf("The largest number is%d
",&m);
   return 0;
}

int max(int x,int y,int z)
{
   int temp;
   if(x>y)
       temp=x;
   else temp=y;
   if(temp>z)
       return(temp);
   else 
       return(z);
}

结果

图片.png

期待结果

原本这个程序是把三个数字中的最大那个输出,但是按下enter键之后光标就到了下一个空行,不知道哪里错了?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

printf 应当传值,而非传址。

- printf("The largest number is%dn",&m);
+ printf("The largest number is%dn", m);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...