Windows平台下GCC编程之从键盘输入3个整数,求其中的最大数和最小数,并输出结果

来源:互联网 发布:ping的端口是多少 编辑:程序博客网 时间:2024/05/17 09:02
代码都是我自己练习写的,如果有什么不妥,自己修改就行了,在Code::Blocks16.01+GCC4.9.2 for Windows上编译运行成功
//1. 从键盘输入3个整数,求其中的最大数和最小数,并输出结果。#include<iostream>using namespace std;void getMaxMin(int a,int b, int c);int main(int argc, char *argv[]){    int a,b, c;    cout<<"Please input 3 numbers:";    cin>>a>>b>>c;    getMaxMin(a,b,c);    return 0;}void getMaxMin(int a,int b, int c){    int max=a;    int min=b;    if(a>b&&b>c)    {        max=a;        min=c;        cout<<"The max number is :"<<max<<endl;        cout<<"The min number is :"<<min<<endl;    }    else if(a>b&&b<c)    {        if(a>c)        {            max=a;            min=b;        }        else if(a<c)        {            max=c;            min=b;        }        cout<<"The max number is :"<<max<<endl;        cout<<"The min number is :"<<min<<endl;    }    else if(b>a&&a>c)    {        max=b;        min=c;        cout<<"The max number is :"<<max<<endl;        cout<<"The min number is :"<<min<<endl;    }    else if(b>a&&a<c)    {        if(b>c)        {            max=b;            min=a;        }        else if(b<c)        {            max=c;            min=a;        }        cout<<"The max number is :"<<max<<endl;        cout<<"The min number is :"<<min<<endl;    }    else if(c>a&&a>b)    {        max=c;        min=b;        cout<<"The max number is :"<<max<<endl;        cout<<"The min number is :"<<min<<endl;    }    else if(c>a&&a<b)    {        if(c>b)        {            max=c;            min=a;        }        else if(c<b)        {            max=b;            min=a;        }        cout<<"The max number is :"<<max<<endl;        cout<<"The min number is :"<<min<<endl;    }}

0 0
原创粉丝点击