C中的根例程
我正在用C编写一个例程。以下是源代码:C中的根例程,c,C,我正在用C编写一个例程。以下是源代码: #include <stdio.h> #include <math.h> //Este es el numpy de C (para seno y coseno, aqui) int raices(float r,float discriminante,float a,float b,float c, float *r1, float *r2) { discriminante=b*b-4*a*c; if(discr
#include <stdio.h>
#include <math.h> //Este es el numpy de C (para seno y coseno, aqui)
int raices(float r,float discriminante,float a,float b,float c, float *r1, float *r2)
{
discriminante=b*b-4*a*c;
if(discriminante<0)
{
printf("Raices complejas\n");
}
else
{
r=sqrt(discriminante);
*r1=(-b+r)/(2*a);
*r2=(-b-r)/(2*a);
}
}
int main(void)
{
float sina,cosa,a,b,g=9.8,v,h,t1,t2,d1,d2;
printf("Ingrese la rapidez y el angulo (>0 y <90):");
scanf("%f,%f",&v,&a);
if(a<0 || a>90)
{
printf("El angulo esta en un rango incorrecto\n");
return 1;
}
printf("Entre la altura final:");
scanf("%f",&h);
sina=sin(a);
cosa=cos(a);
t1=(1/2)*g;
raices((1/2)*g,-v*sina,h,&t1,&t2);
return 0;
}
当我使用*
时,为什么会给我一个错误?
这是我用C编写的第一个程序,所以我真的不知道为什么会发生这种情况。错误在这里:
int raices(float r,float discriminante,float a,float b,float c, float *r1, float *r2)
{
应该是
void raices(float a,float b,float c, float *r1, float *r2)
{
float r;
float discriminante;
raices
接受7
参数:5
浮动和2
指针。您使用3
浮动和2
指针调用它。顺便说一句a
:必须将度转换为弧度。@VaneapiedRahita这是英文站点,无论如何-请与标准库链接以解决此问题。它现在是英文的:/tmp/cc48ZgES.o:在函数raices:proyectil.c:(.text+0x66):引用sqrt'notdefined/tmp/cc48ZgES.o:在函数main:proyectil.c:(.text+0x168):引用sin'notdefined proyectil.c:(.text+0x185):未定义对“cos”的引用2:错误:ld返回1退出status@VanesaPiedrahita尝试为数学库添加gcc选项-lm
。
void raices(float a,float b,float c, float *r1, float *r2)
{
float r;
float discriminante;