给定长度(以厘米为单位)作为输入,任务是将给定长度转换为英尺和英寸
我们可以为此使用长度转换公式-
1 feet = 30.48 cm 1 inche = 2.54 cm
Input-: centimetre = 100 Output -: Length in meter = 3m Length in Kilometer = 0.003km
Start Step 1 -> Declare function to perform conversion double convert(int centimeter) set double inch = 0.3937 * centimetre set double feet = 0.0328 * centimetre print inch and feet Step 2 -> In main() Declare and set int centimetre=20 Call convert(centimetre) Stop
#include <stdio.h> // Function to perform conversion double convert(int centimeter){ double inch = 0.3937 * centimeter; double feet = 0.0328 * centimeter; printf ("Inches is: %.2f \n", inch); printf ("Feet is: %.2f", feet); return 0; } // Driver Code int main() { int centimeter = 20; convert(centimeter); return 0; }
输出结果
Inches is: 7.87 Feet is: 0.66