题解 | 最大最小值

最大最小值

https://www.nowcoder.com/practice/051cbca4504d40f5b20bb891d83ec408

题干解读:给出3个数abc,要求他们的最大最小值并输出.

思路:将他们的值比较后找到最大最小值即可.

#include <iostream>
using namespace std;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    int max=a,min=a;
    if(b>max){
        max=b;
    }else if(b<min){
        min=b;
    }
    if(c>max){
        max=c;
    }else if(c<min){
        min=c;
    }
    cout<<"The maximum number is : "<<max<<endl;
    cout<<"The minimum number is : "<<min;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务