| | |
Problem with working with math in C
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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:
This algorithm may not be perfect, but its a good start. If you have any further questions please feel free to ask.
- Stack Overflow
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
IRC
Channel: irc.daniweb.com
Room: #c, #shell
C Syntax (Toggle Plain Text)
#include <math.h> double degrees_to_radians(double degrees) { double PI = 4.0 * atan(1.0); return degrees * PI / 180.0; }
"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
![]() |
Similar Threads
- Javascript not working in IE7 but running in IE5...cross browser problem plz help (JavaScript / DHTML / AJAX)
- Javascript not working in IE7 but running in IE5...cross browser problem plz help (PHP)
- Ajax Problem - Not working in IE, works perfect in Firefox (JavaScript / DHTML / AJAX)
- Math problem with Pygame (Python)
- dreamweaver problem! please help need to get this working asap!! :) (ASP)
- CSS Working in FF, not in IE problem :) (HTML and CSS)
- C++ problem (C++)
Other Threads in the C Forum
- Previous Thread: A puzzl about function
- Next Thread: Need to make program access a data base primary key number entered by user
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming spoonfeeding stack standard strchr string strings structures suggestions system systemcall test testautomation unix user voidmain() wab win32api windows.h






