gpt4 book ai didi

c - C语言中如何调用void函数

转载 作者:行者123 更新时间:2023-11-30 20:48:33 25 4
gpt4 key购买 nike

好吧,我已经编写了具有四个不同功能的代码,其主要目的是在表格中显示从 0-90 角度的速度的角度、时间、距离。速度由用户输入。但是,当我调用正在创建该函数的 void 函数时,我收到错误“对`create_table'的 undefined reference ”这是我的代码。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define G 9.8 /* gravitation acceleration 9.8 m/s^2 */
#define PI 3.141592654

void create_table(double v);
double Projectile_travel_time(double a, double v);
double Projectile_travel_distance(double a, double v);
double degree_to_radian(double d);

int main(void)
{
int n;
double velocity;

printf ("please enter the velocity at which the projectile is launched (m/sec): ");
n = scanf("%lf" ,&velocity);

if(n != 1)
{
printf("Invlid input. Bye...");
exit(1);
}

while (velocity < 0 )
{
printf ("please enter a positive number for velocity: ");
n = scanf("%lf", &velocity);
if(n != 1)
{
printf("Invlid input. Bye...");
exit(1);
}
}
create_table(velocity);


return 0;
}
void create_table(double v)
{
printf("Angle t d\n");
printf("(deg) (sec) (m)\n");

double a,i;
for( a=0; a<=90; a+=5)
{
for(i=0; i<=2; i++)
{
double t = Projectile_travel_time(a, v);
double s = Projectile_travel_distance(a, v);
printf("%d %d %d\n", a, t, s);

}
}


}
double Projectile_travel_time(double a, double v)
{
double t = ((2*v*sin(degree_to_radian(a)))/(G));
return t;
}
double Projectile_travel_distance(double a, double v)
{
double d = ((v*v)/G)*sin(2*degree_to_radian(a));
return d;
}

double degree_to_radian(double d)
{
double r = d*atan(1) * 4 / 180;
return r;
}

如有任何帮助,我们将不胜感激。谢谢

编辑 我已经编辑了代码,但现在遇到了另一个问题,我的输出完全关闭。我的功能不正确有什么建议吗?

最佳答案

您必须将创建的函数保留在主函数之外

关于c - C语言中如何调用void函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37269658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com