3. Exercise 2
• Write a C++ program to take a depth (in
kilometers) inside the earth as input data;
compute and display the temperature at that
depth in degrees Celsius and Fahrenheit. The
relevant formulas are:
Celsius = 10 x (depth) + 20
Farhrenheit = 1.8 x (Celsius) + 32
4. Exercise 3
• The arithmetic mean of two numbers is the
result of dividing their some by 2. The geometric
mean of two numbers is the square root of their
product. The harmonic mean of two numbers is
the arithmetic mean of their reciprocals. Write a
program that takes two floating point numbers
as inputs and displays these three means.
5. If statement
1. if (condition) 3. if (condition)
statement; statement;
2. if (condition) else if (condition)
statement; statement;
else else
statement; statement;
6. Example
• Write a C++ program to find the roots of the
quadratic equations given its coefficients.
7. Pseudocode
1. Read a,b,c.
2. d=b*b - 4*a*c
3. if(d <0)
Print "No real roots“
else if(d=0)
r = -b/2*a
Print r
else
r1 = (-b+sqrt(d))/2*a
r2 = (-b-sqrt(d))/2*a
Print r1 , r2