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 401,495 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 3,170 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.
Views: 1532 | Replies: 2
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

Help Problem with working with math in C

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2004
Location: Overflow State
Posts: 183
Reputation: Stack Overflow is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 4
Stack Overflow's Avatar
Stack Overflow Stack Overflow is offline Offline
C Programmer

Re: Problem with working with math in C

  #2  
Sep 27th, 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  
Join Date: Apr 2004
Posts: 3,471
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 16
Solved Threads: 138
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Problem with working with math in C

  #3  
Sep 28th, 2004
#include <math.h>
 
 double degrees_to_radians(double degrees)
 {
    double PI = 4.0 * atan(1.0);
    return degrees * PI / 180.0;
 }
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 2:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC