Professional Documents
Culture Documents
Programming Lab 5: - Control Structures: Loops II
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/
=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.