C语言设计案例张传学P58编写分段函数绝对值
发布网友
发布时间:2023-08-08 02:18
我来回答
共1个回答
热心网友
时间:2023-08-15 15:09
5.1得到如下代码:
#include <stdio.h>
int main()
{
double x, y;
scanf ("%lf", &x);
if (x <= 1)y = x+5;
else if (x <= 10)y=x*2;
else y = 3/(x-10);
printf ("%f\n", y);
return 0;
}
5.2得到如下代码:
#include <stdio.h>
int main()
{
int x, y;
scanf ("%d", &x);
if (x > 0)y = x*x;
else y = -x;
printf ("%d\n", y);
return 0;
}
5.3得到如下代码:
#include <stdio.h>
int main()
{
int x, y, z;
scanf ("%d%d%d",&x, &y, &z);
if (x > y)x = y;
if (x > z)x = z;
printf ("%d\n", x);
return 0;
}