converting mathematical equations for c

10

Upload: jm-aseniero

Post on 16-Aug-2015

214 views

Category:

Documents


1 download

DESCRIPTION

Programming in C

TRANSCRIPT

Mathematics is relatively straightforward libraryto use. You must remember to link in the math library at compilation and must #include

A common source of error is in forgetting toinclude the fileSome Mathematical FunctionsFunction Description Argument Type Return Value Typeabs(x) Compute absolute value of x double doubleceil(x) Get smallest integral value that exceeds xdouble doublecos(x) Compute cosine of angle in radiansdouble doubleexp(x) Compute exponential of x double doublelog10(x) Compute log to the base 10 of xdouble doublepow(x) Compute x raised to the power ydouble doublesqrt(x) Compute the square root of xdouble doublefloor(x) Get largest integral value less than xdouble doublesin(x) Compute sine of angle in radiansdouble doubletan(x) Compute tangent of angle in radiansdouble doublelog(x) Compute log(x) double doublePROBLEMGet the length of the 2 short sides of a righttriangle. Compute and display the length ofthe longest side of the right triangle. ANALYSISClearly the problem inputs are the length of the two shorter sides of the right triangle. One output is requested which is the length of the longest. These variables should b e type double because and the inputs and outputs may contain fractional parts. DATA REQUIREMENTSProblem Inputlength_side_one /* length of one short side */length_side_two /* length of one short side */Problem Outputlength_longest_side /*length of longest side */Relevant Mathematical FormulaC2 = a2 + b2 or c = a2 + b2 ALGORITHM DESIGN1. Get the values of the short sides2. Calculate the length of the longest side3. Display the value of the longest sideALGORITHM REFINEMENTSStep 2.1 Using the values of the two short sides length_side_one and length_side_twoassign the square root of the sum of the squares of each of the two short sides to length_longest_sideRelevant Mathematical FormulaC2 = a2 + b2 or c = a2 + b2 Equivalent C Expressiondouble a, b, c;c = sqrt( a*a + b*b);IMPLEMENTATIONSAMPLE OUTPUT