由键盘输入一个形如长方体的盒子的长,宽,高,以及一个圆球的半径,判断该盒子能否完全装下圆球,能输入Y,否则输入N
#include <stdio.h>
void main()
{
int a,b,c,r;
int s;
printf("请输入长宽高:\n");
scanf("%d %d %d",&a,&b,&c);
//printf("\n输入的数是:\n%d %d\n",a,b);
printf("请输入直径:\n");
scanf("%d",&r);
//printf("\n输入的数是:%d\n",r);
//调用函数,找出a,b,c中最小的赋值给s
s = small(a,b);
s = small(s,c);
//判断s和r的大小,r比s大则NO
if(r > s)
{
printf("N");
}
else
{
printf("Y");
}
}
int small(int a,int b)
{
if(a>b)
{
return b;
}
else
{
return a;
}
}
可输入小数版本:
#include <stdio.h>
void main()
{
float a,b,c,r;
float s;
printf("请输入长宽高:\n");
scanf("%f %f %f\t%f",&a,&b,&c,&r);
//printf("\n输入的数是:\n%d %d\n",a,b);
//printf("请输入直径:\n");
//scanf("%d",&r);
printf("\n输入的数是:%.1f\n",r);
//找出a,b中小的赋值给s
if(a - b >= 0)
{
s = b;
}
else
{
s = a;
}
//调用函数
bijioa(s,c,r);
}
void bijioa(float a,float b,float r)
{
//首先判断s和c那个小,把小的和r比较
if(a - b >= 0)
{
//如果r比最小的大则NO
if(r - b >0)
{
printf("N");
}
else
{
printf("Y");
}
}
else
{
if(r - a >=0)
{
printf("N");
}
else
{
printf("Y");
}
}
}
改写版
#include <stdio.h>
void main()
{
float a,b,c,r;
float s;
printf("请输入长宽高:\n");
scanf("%f %f %f\t%f",&a,&b,&c,&r);
//找出a,b中小的赋值给s
if(a - b >= 0)
{
s = b;
}
else
{
s = a;
}
//调用函数
bijioa(s,c,r);
}
void bijioa(float a,float b,float r)
{
if(a - b >= 0)
{
//调用函数
end(r,b);
}
else
{
end(r,a);
}
}
void end(float a,float b)
{
if(a - b > 0)
{
printf("N");
}
else
{
printf("Y");
}
}