编写一个读入五个整数后打印其中最大值和最小值的程序,只使用if函数。 5
2个回答
展开全部
//fadsf adsf
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int max;
int min;
int a;
int b;
int c;
int d;
int e;
cin>>a>>b;
if (a>b)
max=a;
if (a<b)
min=a;
if (a<b)
max=b;
cin>>c;
if (b>c)
max=b;
if (min<c)
min=b;
if (min>c)
min=c;
if (b<c)
max=c;
cin>>d;
if (c>d)
max=c;
if (min<d)
min=c;
if (min>d)
min=d;
if (c<d)
max=d;
cin>>e;
if (d>e)
max=d;
if (min<e)
min=d;
if (min>e)
min=e;
if (d<e)
max=e;
cout<<"在"<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<" 5个数中: "<<"\n";
cout<<"最大的数是: "<<max<<"\n";
cout<<"最小的数是: "<<min<<endl;
return 0;
}
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int max;
int min;
int a;
int b;
int c;
int d;
int e;
cin>>a>>b;
if (a>b)
max=a;
if (a<b)
min=a;
if (a<b)
max=b;
cin>>c;
if (b>c)
max=b;
if (min<c)
min=b;
if (min>c)
min=c;
if (b<c)
max=c;
cin>>d;
if (c>d)
max=c;
if (min<d)
min=c;
if (min>d)
min=d;
if (c<d)
max=d;
cin>>e;
if (d>e)
max=d;
if (min<e)
min=d;
if (min>e)
min=e;
if (d<e)
max=e;
cout<<"在"<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" "<<" 5个数中: "<<"\n";
cout<<"最大的数是: "<<max<<"\n";
cout<<"最小的数是: "<<min<<endl;
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询