编写计算表达式x^2-5x+4值的函数funt,用x作为参数调用此函数,分别计算下面各式的值:y1=x^2-5*×+4,y2=(x+15)^2-5×(x+15)+4,y3=(sinx)^2-5×sinx+4。 **输入格式要求:"%lf" 提示信息:"Input x: " **输出格式要求:"x =\t%5.2f\n" "y1=\t%5.2f\n" "y2=\t%5.2f\n" "y3=\t%5.2f\n" 程序运行示例如下: Input x: 3.5 x = 3.50 y1= -1.25 y2= 253.75 y3= 5.88
时间: 2024-03-24 15:40:35 浏览: 111
二抽取代码MATLAB-HybridNet-ldr2hdr:HybridNet:通过CNN进行ldr2hdr,论文详细信息《HybridNet
以下是函数funt的代码实现:
```c
#include <stdio.h>
#include <math.h>
double funt(double x) {
double y1 = pow(x, 2) - 5 * x + 4;
double y2 = pow(x + 15, 2) - 5 * (x + 15) + 4;
double y3 = pow(sin(x), 2) - 5 * sin(x) + 4;
return y1 + y2 + y3;
}
int main() {
double x;
printf("Input x: ");
scanf("%lf", &x);
double result = funt(x);
printf("x =\t%5.2f\n", x);
printf("y1=\t%5.2f\n", pow(x, 2) - 5 * x + 4);
printf("y2=\t%5.2f\n", pow(x + 15, 2) - 5 * (x + 15) + 4);
printf("y3=\t%5.2f\n", pow(sin(x), 2) - 5 * sin(x) + 4);
printf("funt(x) =\t%5.2f\n", result);
return 0;
}
```
程序运行示例如下:
```
Input x: 3.5
x = 3.50
y1= -1.25
y2= 253.75
y3= 5.88
funt(x) = 258.38
```
阅读全文