Textual Questions and Exercises

REVIEW QUESTIONS AND EXERCISES

1. Average of Three Values

Write the algorithm and draw the flowchart to find the average of given 3 values.

Answer:

1. Read n1, n2 and n3, where n represents number
2. avr = (n1 + n2 + n3) / 3
3. print avr

Flowchart:

Read n1, n2, n3
avr = (n1 + n2 + n3) / 3
Print avr

2. Circle Area and Circumference

Write the algorithm and draw the flowchart to find the area and circumference of a circle of radius r.

Hint: Area= πr²; Circumference = 2πr

Answer:

1. Read r
2. Area = 22/7 * r*r, Circumference = 2*22/7*r
3. Print Area, Circumference

Flowchart:

Read r
Area = 22/7*r*r
Circumference = 2*22/7*r
Print Area, Circumference

3. Temperature Conversion

Write the algorithm and draw the flowchart to convert the temperature given in °C to °F.

Hint: Use the relation °F= 1.8°C +32

Answer:

1. Read c
2. f = 1.8 * c + 32
3. Print f

Flowchart:

Read c
f = 1.8 * c + 32
Print f

4. Smallest of Three Numbers

Draw the flowchart to find the smallest of the given three numbers.

Answer:

Input A, B, C
Is A < B?
Yes
Is A < C?
Yes
Smallest = A
No
Smallest = C
No
Is B < C?
Yes
Smallest = B
No
Smallest = C
Print Smallest

5. Cosine Series Summation

Draw the flowchart to solve the following series which is the summation of cosine series:
s = x - x²/2! + x⁴/4! - x⁶/6! + ... ∞
neglecting the terms which are less than 10⁻⁴ in magnitude.

Answer:

Start
Input x
Set term = x, sum = x, n = 1
Is absolute value of term >= 0.0001?
Yes
Compute next term using: (-1)ⁿ * x²ⁿ / (2n)!
Add term to sum
Increment n
No
Print sum

Hint: The method discussed in Example 8 can be used to solve this series with minor changes.

6. Sum of Natural Numbers

Draw the flowchart to find the sum of natural numbers up to N.

Hint: The method discussed in Example 10 can be used to solve the series, i.e. s = 1 + 2 + 3 + 4 + ... + N.

Answer:

Start
Read N and set S = 0
Set i = 1
Is i <= N?
Yes
S = S + i
i = i + 1
No
Display S

7. Factorial Series

Draw a flowchart to solve the following series:
s = 1 + 1/2! + 1/3! + 1/4! + ... + 1/N!

Answer:

Start
Read N, set S = 1 and i = 2
Is i <= N?
Yes
Set fact = 1
Set j = 1
Is j <= i?
Yes
fact = fact * j
j = j + 1
No
S = S + 1 / fact
i = i + 1
No
Display S

8. Exponential Series (eˣ)

Draw a flowchart to solve the following series:
eˣ = 1 + x + x²/2! + x³/3! + x⁴/4! + ... ∞
Neglect the terms which are less than 10 in magnitude.

Answer:

Start
Read x, set term = 1 and sum = 1, i = 1
Is term >= 10?
Yes
term = term * x / i
sum = sum + term
i = i + 1
No
Display sum

SHORT QUESTIONS

1. What is an algorithm?

Answer: An algorithm presents step-by-step instructions required to solve any problem.

2. What is a flowchart?

Answer: Flowchart is a symbolic or diagrammatic representation of an algorithm.

3. _______ programming method is followed in C language.

Answer: Procedural

4. _______ programming method is followed in C++.

Answer: Object-Oriented

5. Procedural programming method is commonly used for writing small programs which produce discrete results. (True/False)

Answer: True

6. Object-oriented programming method is commonly used to develop software packages to perform a task. (True/False)

Answer: True

7. Algorithms and flowcharts may be omitted after getting experience in writing program. (True/False)

Answer: False