四个整数求最大值问题
2014-05-29 15:49
134 查看
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//求三个数的最大值
/*
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout <<"请输入3个整数:"<<endl;
cin>> a>>b>>c;
if(a > b)
{
if(a > c)
cout << a<<endl;
else
cout << c<<endl;
}
else
{
if(b > c)
cout << b<<endl;
else
cout << c<<endl;
}
return 0;
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//由求三个数的最大值推出求四个数的最大值,该方法容易想到,但是,容易推错,
/*
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d;
cout<< "求四个数的最大值,请输入4个数"<<endl;
cin >>a>>b>>c>>d;
if(a > b)
{
if(a > c)
{
if(a > d)
{
cout << a <<endl;
}
else
cout << d << endl;
}
else
{
if(c > d )
cout << c << endl;
else
cout << d;
}
}
else
{
if(b > c)
{
if(b > d)
cout << b <<endl;
else
cout << d << endl;
}
else
{
if(c > d)
cout << c <<endl;
else
cout << d <<endl;
}
}
return 0;
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 输出四个整数的最大值*/
//引入变量,逐个比较
/*
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,max1;
cout <<"请输入四个整数"<<endl;
cin >> a >> b >> c >> d;
max1 = a;
if(max1 < b)
max1 = b;
if(max1 < c)
max1 = c;
if(max1 < d)
max1 =d;
cout <<"最大值是"<< max1 <<endl;
return 0;
}
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//稍作扩展,求四个数的最大,最小值
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,max,min;
cout <<"请输入4个整数"<<endl;
cin >> a >> b >> c >> d;
max = a;
if(max < b)
max = b;
if(max < c)
max = c;
if(max < d)
max = d;
min = a;
if(min > b)
min = b;
if(min > c)
min = c;
if(min > d)
min = d;
cout <<"最大值为"<< max <<endl;
cout <<"最小值为"<< min <<endl;
return 0;
}
//求三个数的最大值
/*
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout <<"请输入3个整数:"<<endl;
cin>> a>>b>>c;
if(a > b)
{
if(a > c)
cout << a<<endl;
else
cout << c<<endl;
}
else
{
if(b > c)
cout << b<<endl;
else
cout << c<<endl;
}
return 0;
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//由求三个数的最大值推出求四个数的最大值,该方法容易想到,但是,容易推错,
/*
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d;
cout<< "求四个数的最大值,请输入4个数"<<endl;
cin >>a>>b>>c>>d;
if(a > b)
{
if(a > c)
{
if(a > d)
{
cout << a <<endl;
}
else
cout << d << endl;
}
else
{
if(c > d )
cout << c << endl;
else
cout << d;
}
}
else
{
if(b > c)
{
if(b > d)
cout << b <<endl;
else
cout << d << endl;
}
else
{
if(c > d)
cout << c <<endl;
else
cout << d <<endl;
}
}
return 0;
}
*/
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* 输出四个整数的最大值*/
//引入变量,逐个比较
/*
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,max1;
cout <<"请输入四个整数"<<endl;
cin >> a >> b >> c >> d;
max1 = a;
if(max1 < b)
max1 = b;
if(max1 < c)
max1 = c;
if(max1 < d)
max1 =d;
cout <<"最大值是"<< max1 <<endl;
return 0;
}
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//稍作扩展,求四个数的最大,最小值
#include <iostream>
using namespace std;
int main()
{
int a,b,c,d,max,min;
cout <<"请输入4个整数"<<endl;
cin >> a >> b >> c >> d;
max = a;
if(max < b)
max = b;
if(max < c)
max = c;
if(max < d)
max = d;
min = a;
if(min > b)
min = b;
if(min > c)
min = c;
if(min > d)
min = d;
cout <<"最大值为"<< max <<endl;
cout <<"最小值为"<< min <<endl;
return 0;
}
相关文章推荐
- 编程之美 2.7 最大公约数 扩展问题之逆转一个整数的二进制表示
- 第七周任务2-求四个整数中的最大值
- 《编程之美》求两个大整数的最大公约数问题的一般解法
- 输出四个整数的最大值和最小值
- 【转】关于int范围中负数最小值的绝对值比整数最大值大初学C,问题源自:为什么C中的int类型(16位)的下溢下限为-32768而上溢上限却是32767。 首先说吧,32767很容易理解,32767=
- 一道“正方体六个面上的四个角点整数之和相等”的求解问题
- Java:多重循环for、while、do-while(简单判断是否是四位整数、1-100累加,水仙花、最大公约数。最小公倍数、完数、输入任意数计算每位数之和、弹力球问题)
- java中关于整数的一些操作问题--最大公约数、最小公倍数、质数等
- 输出四个整数中的最大值
- 最大子序列问题:给定一整数序列A1,A2,A3...An(可能有负数),求A1~An的一个最大子序列Ai~Aj的和。
- 第七周作业—四个整数选出最大值
- 给出四个整数,求出最大和最小值
- 比较四个整数的大小,找出最大值
- java 之连续子序列最大和问题的四个解法
- 求四个整数中的最大值
- 求整数m的最大加数为n的组合问题
- 输出四个整数中的最大值
- 输入四个整数,输出其中的最大值
- 求两正整数的正差值and求四个整数的最大值和最小值以及由大到小排序
- iOS中的NSString引用计数问题(-1和整数最大值)