GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-Dec-2006, 16:11
ChodyWang ChodyWang is offline
New Member
 
Join Date: Dec 2006
Posts: 4
ChodyWang is on a distinguished road

Changing Radians to Degrees


I'm currently working on a program that uses sine functions that involve degrees. How do you change it so that your computer calculates in degrees instead of radians?
  #2  
Old 23-Dec-2006, 16:55
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,648
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Changing Radians to Degrees


Quote:
Originally Posted by ChodyWang
How do you change it so that your computer calculates in degrees

If you want to write a program using the standard C library sin() to calculate the sine of a value, the value must be in radians.

If you are given a value in degrees, you must convert the value to radians.

Code:
(value in radians) = (value in degrees) * (number of radians per degree)

Where the number of radians per degree is equal to pi/180.

Now, the C language doesn't know about pi, so you must tell it.

CPP / C++ / C Code:
#include <stdio.h>
#include <math.h>
int main()
{

    double pi = 3.14159265358979323846;
    double xdegrees;
    double xradians;

    printf("pi = %.16f\n", pi);
    printf("sin(pi / 6.0) = %f\n", sin(pi / 6.0));
    xdegrees = 30;
/* put a statement here that sets xradians equal to pi/180 times xdegrees */
    printf("sin of %.1f degrees = sin(%f) = %f\n", 
            xdegrees, xradians, sin(xradians));
    return 0;
}

Output:

Code:
pi = 3.1415926535897931 sin(pi / 6.0) = 0.500000 sin of 30.0 degrees = sin(0.523599) = 0.500000

Regards,

Dave
Last edited by davekw7x : 23-Dec-2006 at 17:38.
  #3  
Old 23-Dec-2006, 18:12
ChodyWang ChodyWang is offline
New Member
 
Join Date: Dec 2006
Posts: 4
ChodyWang is on a distinguished road

Re: Changing Radians to Degrees


Thanks. a lot that helps
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Text Colors Or Look In C++ mfm1983 C++ Forum 4 19-Dec-2006 06:27
Convert Fahrenheit to Celsius and Kelvin ajguerrero C Programming Language 2 19-Apr-2006 06:58
Changing PHP list link color crystalattice Web Design Forum 4 20-Jan-2006 22:54
Changing focus from one tab to another tab control vijji MS Visual C++ / MFC Forum 1 23-Nov-2005 07:14
changing colour of individual items of control created through CListCtrl Sadia MS Visual C++ / MFC Forum 0 01-Jul-2005 08:09

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:45.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.