Professional Documents
Culture Documents
Program: 1. Calculation of Average of Numbers
Program: 1. Calculation of Average of Numbers
)%m / 0 & #$%n" / 0 & 12i(e( #$%n" 3 N ! )#anf(45f4* 6n%m.e, & )%m / )%m 7 n%m.e, & #$%n" / #$%n" 7 1 & 8
8 Output
a+e,a-e / )%m/N & 9,in"f(4N / 5d S%m / 5f4* N* )%m & 9,in"f(4 A+e,a-e / 5f4* a+e,a-e &
S%m / <@;?BBBBB
A+e,a-e / <;@@0000
variable count counts the number of values and as soon as it becomes 11 the while loop is e!ited and then the average is calculated. Notice that the actual value of sum is "#.# but the value displayed is "#.$%%%%%. &n fact the actual value that is displayed is 'uite dependent on the computer system. Such an inaccuracy is due to the (ay the floating point numbers are internally represented inside the computer. 2. Temperature Conversion Problem The program presented in Fig.2.12 converts the given temperature in fahrenheit to celsius using the follo(ing conversion formula) F * "2 + , ************ 1.#
FACRENCEIT D CELSIUS CONVERSION TABLE EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE Program #define #define #define FELOF FEMAG STEH 0 :A0 :A /* DDDDDDDDDDDDDDDDDDDDD */ /* SYMBOLIC CONSTANTS */ /* DDDDDDDDDDDDDDDDDDDDD */
*/ */
fa2,en2ei" / FELOF & /* INITIALI0ATION */ 9,in"f(4Fa2,en2ei" Ce()i%)JnJn4 & 12i(e( fa2,en2ei" 3/ FEMAG ! #e()i%) / ( fa2,en2ei" D <:;0 / 1;@ & 9,in"f(4 5A;1f 5?;:fJn4* fa2,en2ei"* #e()i%) & fa2,en2ei" / fa2,en2ei" 7 STEH & 8
Output Fa2,en2ei" 0;0 :A;0 A0;0 ?A;0 Ce()i%) D1?;?@ D<;@B 10;00 :<;@B
---------------------------------------------------------------