罪() [英] Sin ()

查看:60
本文介绍了罪()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

G''day


我正在努力计算斜边的长度。附件是我正在使用的

代码:


#include< stdio.h>

#include< math .h>


double hypUsingTrig(double e)

{

double x;

x =双重罪(37);

返回e / x;

}


main(){

printf(最后的斜边是:%f \ n,hypUsingTrig(3));

}


答案即将到来作为-4.661728,但我不认为这是正确的。

无论如何,我可以检查我的答案。


格雷格

G''day

I am trying to work out the length of the hypotenuse. Attached is the
code that I am using:

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

double hypUsingTrig(double e)
{
double x;
x= double sin(37);
return e/x;
}

main() {
printf("The final hypotenuse is:%f\n", hypUsingTrig(3));
}

The answer is coming up as -4.661728 but I don''t think it is correct.
Is there anyway method that I could check my answer.

Greg

推荐答案

Gregc。说:
Gregc. said:
G''day

我想弄清楚斜边的长度。


哪个斜边?

附件是我正在使用的代码:

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

double hypUsingTrig(double e)
{
double x;
x = double sin(37);
返回e / x;
}

main(){
printf(最后的斜边是:%f \ n,hypUsingTrig(3));
}

答案是-4.661728,但我不认为这是正确的。
G''day

I am trying to work out the length of the hypotenuse.
Which hypotenuse?
Attached is the code that I am using:

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

double hypUsingTrig(double e)
{
double x;
x= double sin(37);
return e/x;
}

main() {
printf("The final hypotenuse is:%f\n", hypUsingTrig(3));
}

The answer is coming up as -4.661728 but I don''t think it is correct.




我'令人印象深刻的是,你甚至得到了答案。在这里,它是
没有编译:


gcc -W -Wall -ansi -pedantic -O2 -g -pg -c -o foo .o foo.c

foo.c:在函数`hypUsingTrig'':

foo.c:7:在'double'之前解析错误'

foo.c:6:警告:x可能在此函数中未初始化使用

foo.c:顶级:

foo.c: 11:警告:return-type默认为'int''

foo.c:在函数`main''中:

foo.c:13:警告:控制到达无效功能结束

make:*** [foo.o]错误1


一旦你解决了这个小故障,你我不妨回想一下sin()

需要一个弧度角度,而不是度数。


#define PI 3.14159 / *调整到味道* /


double deg_to_rad(双度)

{

double rad = deg * PI / 180.0;

}


-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

电子邮件:rjh在上面的域名(但显然放弃了www)



I''m impressed that you''re even getting an answer at all. Over here, it
didn''t compile:

gcc -W -Wall -ansi -pedantic -O2 -g -pg -c -o foo.o foo.c
foo.c: In function `hypUsingTrig'':
foo.c:7: parse error before `double''
foo.c:6: warning: `x'' might be used uninitialized in this function
foo.c: At top level:
foo.c:11: warning: return-type defaults to `int''
foo.c: In function `main'':
foo.c:13: warning: control reaches end of non-void function
make: *** [foo.o] Error 1

Once you''ve sorted out that little glitch, you may wish to recall that sin()
takes an angle in radians, not degrees.

#define PI 3.14159 /* adjust to taste */

double deg_to_rad(double deg)
{
double rad = deg * PI / 180.0;
}

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)


" Gregc。 < GR ********* @ bigpond.com>写道:
"Gregc." <gr*********@bigpond.com> writes:
我正在尝试计算斜边的长度。随附的是我正在使用的代码:

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

双hypUsingTrig(double e)
{
双x;
x =双重罪(37);
返回e / x;
}
main(){
printf(最后的斜边是:%f \ n,hypUsingTrig(3));
}

答案即将出现-4.661728但我不认为这是正确的。
无论如何我可以检查我的答案。
I am trying to work out the length of the hypotenuse. Attached is the
code that I am using:

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

double hypUsingTrig(double e)
{
double x;
x= double sin(37);
return e/x;
}

main() {
printf("The final hypotenuse is:%f\n", hypUsingTrig(3));
}

The answer is coming up as -4.661728 but I don''t think it is correct.
Is there anyway method that I could check my answer.




如果您有任何疑问你的代码,发布你的代码。发布

类似于你的代码,正如你在这里所做的那样,浪费了每个人的时间。当您发布代码时,您需要复制并粘贴您编译的

* exact *代码。不要试图重新输入它。不要用

我们猜猜你的原始代码中有哪些错误,以及你发布时引入的错误




我尝试编译你发布的代码。我的编译器在行上报了一个语法

错误


x = double sin(37);


我'我猜这应该是


x =(double)sin(37);


随着这一变化,代码编译和产生与你报告的相同的输出

。如果我猜错了,接下来的大部分内容都将是无用的。


任何演员都应该怀疑。这个演员特别是

完全没必要。 sin函数返回一个类型为

double的值;将它转换为double是没有用的。


你可以更清楚地编写你的hypUsingTrig而不使用

中间变量:


double hypUsingTrig(double e)

{

return e / sin(37);

}

您应该更改main()到int main(void),你应该添加一个

" return 0;"就在闭幕式之前。


随着这些变化(以及一些化妆品格式的变化),你的

计划变为:

================================

#include< stdio.h>

#include< math.h>


double hypUsingTrig(double e)

{

返回e / sin(37);

}


int main(无效)

{

printf(最后的斜边是:%f \ n,hypUsingTrig(3));

返回0;

}

================================


这是很长一段时间以来我研究了三角学,而且我不记得所有的公式都在我脑海中。更具描述性的

名称将非常有用。请记住,变量名称不是限于单个字母,而是因为e和e。名称是一个

数学常量,在程序中使用它作为变量名称

三角函数特别令人困惑。评论也可以是

有用。


你有两个魔术数字在你的代码中,37和3,并没有明显的

表示它们代表什么。可能hypUsingTrig应该使用两个参数,并且你应该把它称为hypUsingTrig(3,37)。给参数(边缘和角度,可能是?)提供

有意义的名称将使b / b
使代码更容易理解。


我强烈怀疑你问题的真正根源是sin()

函数'的参数用弧度表示,而不是度。我怀疑你对b-radian顶点的直角三角形感兴趣

(大约是2220度)。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



If you have a question about your code, post your code. Posting
something similar to your code, as you''ve done here, is a waste of
everyone''s time. When you post code, you need to copy-and-paste the
*exact* code that you compiled. Don''t try to re-type it. Don''t make
us guess which errors are in your original code, and which errors you
introduced when you posted it.

I tried compiling the code you posted. My compiler reported a syntax
error on the line

x= double sin(37);

I''m guessing that this was supposed to be

x = (double)sin(37);

With that change, the code compiles and produces the same output that
you reported. If I''ve guessed incorrectly, much of what follows will
be useless.

Any cast should be viewed with suspicion. This cast in particular is
completely unnecessary. The sin function returns a value of type
double; casting it to double serves no purpose.

Your hypUsingTrig can be written more clearly without using an
intermediate variable:

double hypUsingTrig(double e)
{
return e / sin(37);
}

You should change "main()" to "int main(void)", and you should add a
"return 0;" just before the closing brace.

With those changes (and a couple of cosmetic formatting changes), your
program becomes:
================================
#include <stdio.h>
#include <math.h>

double hypUsingTrig(double e)
{
return e / sin(37);
}

int main(void)
{
printf("The final hypotenuse is: %f\n", hypUsingTrig(3));
return 0;
}
================================

It''s been a long time since I studied trigonometry, and I don''t
remember all the formulas off the top of my head. More descriptive
names would be very helpful. Keep in mind that variable names are not
limited to single letters -- and since "e" the name of is a
mathematical constant, using it as a variable name in a program that
does trigonometry is particularly confusing. Comments can also be
helpful.

You have two "magic numbers" in your code, 37 and 3, and no obvious
indication of what they represent. Possibly hypUsingTrig should take
two arguments, and you should call it as hypUsingTrig(3, 37). Giving
meaningful names to the parameters ("edge" and "angle", maybe?) would
make the code much easier to follow.

I strongly suspect the real source of your problem is that the sin()
function''s argument is expressed in radians, not degrees. I doubt
that you''re interested in a right triangle with a 37-radian vertex
(that''s about 2220 degrees).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.




Gregc。 < GR ********* @ bigpond.com>在消息中写道

news:11 ********************** @ j33g2000cwa.googlegr oups.com ...

"Gregc." <gr*********@bigpond.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
G''day

我正试图计算出斜边的长度。随附的是我正在使用的代码:

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

双hypUsingTrig(double e)
{
double x;
x = double sin(37);


正弦函数以弧度为单位。你可能

想要37度。


弧度角度=角度度数* PI​​ / 180

其中PI为3.14159等。或


双PI = 4 * atan(1.0);

---- WHG
G''day

I am trying to work out the length of the hypotenuse. Attached is the
code that I am using:

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

double hypUsingTrig(double e)
{
double x;
x= double sin(37);
The sine function takes argument in radians. You probably
wanted 37 degrees.

angle in radians = angle in degrees * PI / 180
where PI is 3.14159 etc. or

double PI = 4 * atan(1.0);
---- W H G



这篇关于罪()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆