您的位置:首页 > 编程语言

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

2016-04-13 14:05 633 查看
代码都是我自己练习写的,如果有什么不妥,自己修改就行了,在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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ 编程 gcc