943,482 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 8589
  • C RSS
Oct 8th, 2004
0

Math problem in C

Expand Post »
Hi! I had 1 problem in C, now I have another one. :o
Please bear with me. I am learning the C language.

Please run the following calculation in a scientific calculator. When the "=" sign is shown at the end of the calculation, be sure to press the = button on the calculator. Asin is labeled Sin -1 on some calculators. It dosn't matter if you don't have a scientific calculator.

((292.797 sin)*0.39777)asin=

The answer should be: -21.6685752754108925

Here is the same calculation in C. This is the way I do it:

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

main()
{
double math;

math=sin(292.797) * asin(0.39777);

printf("The result is %f",math);

return 0;

}

Ok, why aren't the 2 calculations the same? I need them the same. I have tried using different types of variables, I have tried converting radians to degrees, (math * 180 / PI) I have tried other things too, but to no avail. I have even tried doing a simple calculation like the following, to see if I did a mistype:

math=sin(1);

Even the above problem won't compute the same. It'll work fine for the basic calculations (+, -. x, -).

I think my problem might be converting radians to degrees (not sure). I have heard several calculations on converting radian numbers to degrees, and I have tried all of them. None have seemed to work.

I would appreciate ANY help on how I can get the 2 calculations to be the same.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ray96 is offline Offline
5 posts
since Sep 2004
Oct 8th, 2004
0

Re: Math problem in C

Hi Ray,

it looks like your caculator is in RPN (a.k.a. Reverse Polish Notation) mode.

In order to relect the same sequence of operations in C, you should convert to standard notation:

asin (0.39777 * sin (292.797)) If you then wanted to convert the answer into Degrees instead of radians, simply multiply the answer by 180 / PI.

PI = 3.14.....
180 / PI * asin (0.39777 * sin (292.797))

I hope I understood your question. and I hope this helps.


Ed

Quote originally posted by ray96 ...

((292.797 sin)*0.39777)asin=

The answer should be: -21.6685752754108925
Reputation Points: 17
Solved Threads: 1
Junior Poster
cosi is offline Offline
153 posts
since Aug 2004
Oct 9th, 2004
0

Re: Math problem in C

Thank You for your response! I will try what you said
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ray96 is offline Offline
5 posts
since Sep 2004
Oct 10th, 2004
0

Re: Math problem in C

You have to be careful with radians and degrees, don't get them mixed up!

  1. // result is supposed to be -21.6685752754108925 ?
  2. // my casio calculator and the computer says -21.51209184
  3.  
  4. #include <stdio.h>
  5. #include <math.h>
  6.  
  7. int main(void)
  8. {
  9. double math, PI, x;
  10.  
  11. PI = atan(1) * 4.0; // a little old fashioned trickery to get PI
  12. x = 292.797 * PI/180; // degrees to radians
  13.  
  14. math = asin(sin(x) * 0.39777);
  15.  
  16. printf("The result is %f radians",math);
  17.  
  18. math = math * 180 / PI; // radians back to degrees
  19.  
  20. printf("\nThe result is %f degrees",math);
  21.  
  22. getchar();
  23. return 0;
  24. }
You may have slipped on one of them darn numbers on those tiny calculator keys, hombre! Close enough! Remember, computers never make missteaks!
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: unhandaled exception,0X000005:access violation
Next Thread in C Forum Timeline: can ANYONE help? need to make a queue





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC