问题描述
我必须计算角度测量和n-gon的周长。我必须使用余弦来计算剩余的一面,我不断收到一个错误,说这是对cosf的一个未定义的引用,我已经做了一些编辑,我老实说无法解决这个问题
I'm having to calculate the angle measure and perimeter of a n-gon. I have to use cosine to calculate the remaining side and I keep getting an error saying that it's an undefined reference to cosf, and i've done some editting around, I honestly can't figure this out
#include <stdio.h>
#include <math.h>
int main(void)
{
float sides, radius, side, perimeter, perimeterFeet, rads;
float sideLength = 0;
double x, angle;
printf("Enter the number of sides on the polygon: ");
scanf("%f", &sides);
printf("Enter the radius of the polygon: ");
scanf("%f", &radius);
angle = (sides-2)/sides * 180;
rads = angle * 0.01745329252;
x = double cos(angle);
sideLength = radius*radius + radius*radius - 2 * radius * radius * x;
sideLength = sqrtf(sideLength);
perimeter - sideLength* sides;
perimeterFeet = perimeter/12;
printf("Angle is %f radians (%f degrees) \n", rads, angle);
printf("The side is %f inches \n", sideLength);
printf("The perimeter is %f inches and %f feet", perimeter, perimeterFeet);
}
我的尝试:
我试过改变cos到cosf,双cos(双角),cos(双角),cos(角)我在这里难倒
What I have tried:
I've tried changing around cos to cosf, double cos(double angle), cos(double angle), cos(angle) I'm stumped here
推荐答案
gcc -o main *.c -lm
并在此行中将 double
转换为演员(double)
:
And either convert double
to a cast (double)
in this line:
x = double cos(angle);
或者删除它。
你可能想要从 sqrtf
中删除'f':
Or remove it.
You probably want to remove the 'f' from sqrtf
as well:
sideLength = sqrt(sideLength);
这篇关于在C中计算时使用余弦时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!