Problem with working with math in C

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2004
Posts: 5
Reputation: ray96 is an unknown quantity at this point 
Solved Threads: 0
ray96 ray96 is offline Offline
Newbie Poster

Problem with working with math in C

 
0
  #1
Sep 27th, 2004
Hi, I am very new to C, and also to this forum, so please bear with me. :!: :o I am trying to create a console astronomical program, and I need to know how to convert radian numbers to degrees. I would appreciate any help.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 185
Reputation: Stack Overflow is an unknown quantity at this point 
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: Problem with working with math in C

 
0
  #2
Sep 28th, 2004
Greetings ray96,

Mathematics in C is not difficult to use. For example, lets take this word problem for example:

Note: Since 360° = 2 radians, then 180° = radians.
We will use this fact to convert between degrees and radians.

» Convert 5/12 radians to degrees.
Lets take a simple approach:

Step 1: 5 rads / 12
Step 2: 180 degs / rads

Step 3: 5 x 180degs / 12
Step 4: 75 degrees

Doing this in C wont be hard at all:

int radToDegrees(int radians) {
	float s1;

	s1 = (radians * 180.0f) / 12.0f;

	return (int)s1;
}

This algorithm may not be perfect, but its a good start. If you have any further questions please feel free to ask.

- Stack Overflow
Following the rules will ensure you get a prompt answer to your question. If posting code, please include BB [code][/code] tags. Your question may have been asked before, try the search facility.

IRC
Channel: irc.daniweb.com
Room: #c, #shell
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,438
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 249
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Problem with working with math in C

 
0
  #3
Sep 28th, 2004
  1. #include <math.h>
  2.  
  3. double degrees_to_radians(double degrees)
  4. {
  5. double PI = 4.0 * atan(1.0);
  6. return degrees * PI / 180.0;
  7. }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC