任意输入3个数,输出其中最大的数和最小的数 c++语言
2个回答
展开全部
这是纯if else语句,我建议不要这样写
#include<stdio.h>
void main()
{
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if(a>b)
{
if(a>c)
{
printf("the max is %d \n",a);
if(b>c)
{
printf("the min is %d \n",c);
}
else
{
printf("the min is %d \n",b);
}
}
else
{
printf("the max is %d \n",c);
if(a>b)
{
printf("the min is %d \n",b);
}
else
{
printf("the min is %d \n",a);
}
}
}
else
{
if(b>c)
{
printf("the max is %d \n",b);
if(a>c)
{
printf("the min is %d \n",c);
}
else
{
printf("the min is %d \n",a);
}
}
else
{
printf("the max is %d \n",c);
if(a>b)
{
printf("the min is %d \n",b);
}
else
{
printf("the min is %d \n",a);
}
}
}
getch();
}
#include<stdio.h>
void main()
{
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if(a>b)
{
if(a>c)
{
printf("the max is %d \n",a);
if(b>c)
{
printf("the min is %d \n",c);
}
else
{
printf("the min is %d \n",b);
}
}
else
{
printf("the max is %d \n",c);
if(a>b)
{
printf("the min is %d \n",b);
}
else
{
printf("the min is %d \n",a);
}
}
}
else
{
if(b>c)
{
printf("the max is %d \n",b);
if(a>c)
{
printf("the min is %d \n",c);
}
else
{
printf("the min is %d \n",a);
}
}
else
{
printf("the max is %d \n",c);
if(a>b)
{
printf("the min is %d \n",b);
}
else
{
printf("the min is %d \n",a);
}
}
}
getch();
}
展开全部
#include <iostream>
using namespace std;
int main(){
double a, b, c, temp;
if(a < b){
temp = a;
a = b;
b = temp;
}
if(b < c){
temp = b;
b = a;
a = temp;
}
if(a < c){
temp = a;
a = c;
c = temp;
}
cout <<a <<" " <<c<<endl;
return 0;
}
using namespace std;
int main(){
double a, b, c, temp;
if(a < b){
temp = a;
a = b;
b = temp;
}
if(b < c){
temp = b;
b = a;
a = temp;
}
if(a < c){
temp = a;
a = c;
c = temp;
}
cout <<a <<" " <<c<<endl;
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |