注册 登录
编程论坛 C++教室

3个数比较大小输出最大值,为什么这个不对呢?求大神啊

原一一 发布于 2015-04-02 13:54, 625 次点击
#include <stdio.h>
void mian()
{
    int a,b,c,max;
    printf("Please enter a,b,c:");
    scanf("%d%d%d",&a,&b,&c);
    if(a>b)   
        max=a;
    else max=b;
    if(max>c)
        max=c;
    return(max);
    printf("max=%d\n",max);
}
6 回复
#2
bravetang2015-04-02 14:14
return(max);//这句程序不就结束了吗?你当然不能看到程序结果了。
#3
yangfrancis2015-04-03 13:34
if(max>c)
        max=c;
什么逻辑
#4
创世写生2015-04-05 15:03
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,max;
        cout<<"请输入三个数:"<<endl;                               这个是用C++编的,C语言结构与其类似
    cin>>a>>b>>c;
    if(a>b)
    max=a;
    else
    max=b;
    if(c>max)
    max=c;
    cout<<max<<endl;

}
#5
创世写生2015-04-05 15:04
回复 4楼 创世写生
你的错误就在于 return的位置不对  ,还有你没有输出内容 ,最严重的就是算法出错了
#6
紫苑小七2015-04-05 18:55
if(max>c)
        max=c;这句 错了,并且return语句 应该放到该方法最后
#7
sgyr2015-04-05 20:21
#include <stdio.h>
 void mian()
 {
     int a,b,c,max;
     printf("Please enter a,b,c:");
     scanf("%d%d%d",&a,&b,&c);
     if(a>b)   
         max=a;
     else max=b;
     if(max<c)
         max=c;
     printf("max=%d\n",max);

 } 难道不该这样吗 而且你的是无返回值 干嘛要一个return
1