Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

代码

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

    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键之后光标就到了下一个空行,不知道哪里错了?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.9k views
Welcome To Ask or Share your Answers For Others

1 Answer

printf 应当传值,而非传址。

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...