Write a program that takes as input given lengths expressed in feet and inches. The program should then convert and output the lengths in centimeters. Assume that the given lengths in feet and inches are integers.
Input Length in feet and inches.
Output Equivalent length in centimeters.
For example, suppose the input is 5 feet and 7 inches. You then find the total inches as follows:
totalInches = (12 * feet) + inches
= 12 * 5 + 7
= 67
You can then apply the conversion formula, 1 inch 5 2.54 centimeters, to find the length in centimeters.
centimeters = totalInches * 2.54
= 67 * 2.54
= 170.1
Based on this analysis of the problem, you can design an algorithm as follows:
1. Get the length in feet and inches.
2. Convert the length into total inches.
3. Convert total inches into centimeters.
4. Output centimeters.
Comments
Post a Comment