//power.c #include <math.h> #include”compute.h” int main() { float x,y; printf("本程序从标准输入获取x和y的值并显示x的y次方.\n"); printf("请输入浮点数x:"); scanf("%f",&x); printf("请输入浮点数y:"); scanf("%f",&y); printf("x的y次方是:%6.3f\n",compute( (double)x, (double)y )); return 0; } //compute.h double compute(double x, double y); //compute.c #include<math.h> double compute(double x, double y) { return (pow( (double)x,(double)y )); } (1)写出编译上述程序的命令; (2)运行上述程序,写出实验参数和实验结果 (3)利用make工具编译由上述两个文件所组成的程序,写出对应的makefile文件,并写出实验参数和实验结果。
时间: 2023-11-22 15:55:43 浏览: 11
(1) 编译命令:gcc -o power power.c compute.c -lm
其中 -lm 参数表示链接 math.h 库。
(2) 实验参数:输入 x=2,y=3。
实验结果:输出 x 的 y 次方,即 8.000。
(3) makefile 文件如下:
```
power: power.c compute.c
gcc -o power power.c compute.c -lm
clean:
rm power
```
实验参数和实验结果同上。执行 make 命令即可编译程序。
相关问题
//power.c #include <math.h> #include”compute.h” int main() { float x,y; printf("本程序从标准输入获取x和y的值并显示x的y次方.\n"); printf("请输入浮点数x:"); scanf("%f",&x); printf("请输入浮点数y:"); scanf("%f",&y); printf("x的y次方是:%6.3f\n",compute( (double)x, (double)y )); return 0; } //compute.h double compute(double x, double y); //compute.c #include<math.h> double compute(double x, double y) { return (pow( (double)x,(double)y )); } 利用make工具,写出对应的makefile文件,并写出实验参数和实验结果。
下面是对应的makefile文件:
```
CC = gcc
CFLAGS = -Wall -g
OBJECTS = compute.o power.o
all: power
power: $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $(OBJECTS) -lm
compute.o: compute.c compute.h
$(CC) $(CFLAGS) -c compute.c
power.o: power.c compute.h
$(CC) $(CFLAGS) -c power.c
clean:
rm -f *.o power
```
实验参数:
输入 x = 2,y = 3
实验结果:
```
本程序从标准输入获取x和y的值并显示x的y次方.
请输入浮点数x:2
请输入浮点数y:3
x的y次方是:8.000
```
#include <PID_v1.h>常用函数
常用函数如下:
1. `PID` 构造函数:`PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);`
其中,`Input` 是输入值的指针,`Output` 是输出值的指针,`Setpoint` 是设定值的指针,`Kp`、`Ki`、`Kd` 分别是比例、积分、微分系数,`DIRECT` 表示方向,`DIRECT` 为 `true` 时,表示正向控制,为 `false` 时,表示反向控制。
2. `Compute()` 函数:`myPID.Compute();`
该函数用于计算输出值,需要在主循环中反复调用。
3. `SetMode()` 函数:`myPID.SetMode(AUTOMATIC);`
该函数设置 PID 控制器的模式,`AUTOMATIC` 表示自动模式,`MANUAL` 表示手动模式。
4. `SetOutputLimits()` 函数:`myPID.SetOutputLimits(0, 255);`
该函数设置输出范围,防止输出值超出范围。
5. `SetSampleTime()` 函数:`myPID.SetSampleTime(100);`
该函数设置采样时间,单位为毫秒。
6. `SetTunings()` 函数:`myPID.SetTunings(Kp, Ki, Kd);`
该函数设置 PID 控制器的参数。
7. `SetControllerDirection()` 函数:`myPID.SetControllerDirection(DIRECT);`
该函数设置控制器的方向,与 `PID` 构造函数中的 `DIRECT` 参数相同。
8. `GetKp()`、`GetKi()`、`GetKd()` 函数:分别用于获取比例、积分、微分系数的值。
9. `GetMode()` 函数:用于获取当前 PID 控制器的模式(自动或手动)。
10. `GetOutputSum()` 函数:用于获取积分项之和。
11. `GetError()` 函数:用于获取当前误差值。
12. `GetSetpoint()` 函数:用于获取设定值。