Professional Documents
Culture Documents
Assignment 02
Objectives:
To comprehend basic programming skills
Get familiar with the use of repetition control structure
Prerequisite Skills:
Knowledge of C’s basic constructs (expressions, operators, if-else control structure)
Understanding about working of repetition control structures (for, while, do while)
Overview
Euler’s number, e, is used as the base of natural logarithms. It can be approximated using the
following formula.
e = 1 / 0! +1 / 1! + 1/ 2! + 1/ 3! +.....................+ 1/ (n-1)! + 1/ n!
Problem Statement
Write a program that approximate e using a loop that terminates when the difference between two
successive values of e is less than or equal to n where n is a floating-point number i.e., 0.00001 or
0.001
Input Output
0.0000001 2.718282
0.01 2.708333
Assignment 02 Page 1 of 2
CC-112 Programming Fundamentals SPRING 2022
Statisticians use many different algorithms in addition to the arithmetic average. Two other
averages are the arithmetic and harmonic mean. The geometric mean of a set of n numbers, x1 , x2 ,
x3 , x4 , ……………. xn-1, xn is defined by the following formula:
n x1 * x2 * x3 * ........ * xn
The harmonic mean is defined by the following formula:
n
1 1 1 1
x x x ........ x
1 2 3 n
Problem Statement
Write a program that reads series of positive numbers and calculates the average, geometric and
harmonic means.
Input Output
6 Arithmetic mean = 13
20 Geometric mean = 11.771
16 Harmonic mean = 10.551
10
-1
17 Arithmetic mean = 33
22 Geometric mean = 22.231
33 Harmonic mean = 14.453
88
5
-1
Extra Credit:
Extra credit will be awarded for the output formatting (alignment, floating point precision)
File(s) to be submitted:
euler.c, mean.c source code of the programs will be submitted to Teacher Assistant in the
electronic format i.e. softcopy.
Assignment 02 Page 2 of 2