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; } }