You are on page 1of 1

Programming Lab 5 - Control structures: loops II

Task 1
Write a computer program that uses an infinite loop to:
1. Input a zero-terminated list of values.
2. Negative values should be ignored.
3. Output the sum of the reciprocals of the values, R
according to:

1/

Input a value: 1.6


Input a value: 5.6
Input a value: 3.4
Input a value: -5.5
Negative value ignored!
Input a value: 5.5
Input a value: 0
R = 1.279507

=1
Check that your program works correctly (for the values given in the table).

Task 2
An Armstrong number is an integer such that the sum of the cubes of its digits is equal to
the number itself. For example, 371 is an Armstrong number since 3 3 + 73 + 13 = 371.
Write a C++ program to find all Armstrong numbers in the range of 0 and 999.
Hint: nest the loops i=0,9; j=0,9; and k=0,9;
and use the counters to form three-digit decimal numbers ijk.

You might also like