943,447 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2240
  • C RSS
Sep 27th, 2004
0

Problem with working with math in C

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ray96 is offline Offline
5 posts
since Sep 2004
Sep 28th, 2004
0

Re: Problem with working with math in C

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
Reputation Points: 26
Solved Threads: 4
Junior Poster
Stack Overflow is offline Offline
185 posts
since Sep 2004
Sep 28th, 2004
0

Re: Problem with working with math in C

  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. }
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 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: A puzzl about function
Next Thread in C Forum Timeline: Need to make program access a data base primary key number entered by user





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


Follow us on Twitter


© 2011 DaniWeb® LLC