User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 425,980 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,656 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 5243 | Replies: 3
Reply
Join Date: Sep 2004
Posts: 5
Reputation: ray96 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ray96 ray96 is offline Offline
Newbie Poster

Math problem in C

  #1  
Oct 7th, 2004
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2004
Location: Hanover
Posts: 152
Reputation: cosi is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
cosi's Avatar
cosi cosi is offline Offline
Junior Poster

Re: Math problem in C

  #2  
Oct 8th, 2004
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

Originally Posted by ray96

((292.797 sin)*0.39777)asin=

The answer should be: -21.6685752754108925
In a world without walls or fences,
What use are Windows and Gates.
Reply With Quote  
Join Date: Sep 2004
Posts: 5
Reputation: ray96 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ray96 ray96 is offline Offline
Newbie Poster

Re: Math problem in C

  #3  
Oct 9th, 2004
Thank You for your response! I will try what you said
Reply With Quote  
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,468
Reputation: vegaseat will become famous soon enough vegaseat will become famous soon enough 
Rep Power: 10
Solved Threads: 176
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
Kickbutt Moderator

Solution Re: Math problem in C

  #4  
Oct 10th, 2004
You have to be careful with radians and degrees, don't get them mixed up!

// result is supposed to be -21.6685752754108925 ?
// my casio calculator and the computer says -21.51209184

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

int main(void)
{
  double math, PI, x; 
  
  PI = atan(1) * 4.0;    // a little old fashioned trickery to get PI
  x = 292.797 * PI/180;  // degrees to radians
  
  math = asin(sin(x) * 0.39777);

  printf("The result is %f radians",math); 
  
  math = math * 180 / PI;   // radians back to degrees 

  printf("\nThe result is %f degrees",math);
  
  getchar();
  return 0;
}
You may have slipped on one of them darn numbers on those tiny calculator keys, hombre! Close enough! Remember, computers never make missteaks!
May 'the Google' be with you!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 11:27 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC