/* convert.c This program converts an integer given by the user from the English unit of measure, inches, to the Metric System units; cm, m, and km. This program may not reflect all the requirements of the C Coding Standards used in this class. */ #include <stdio.h> int main() { int inches; float meters; printf("This program will convert inches into the Metric System.\n"); printf("Please enter an integer: "); scanf("%d", &inches); /* By multiplying an integer (inches) by a float (.0254), the result is a float (meters). If meters was declared as an int, the decimal places would be truncated. */ meters = inches * .0254; printf("Conversion of %d inches into metric yields:\n", inches); printf(" %f centimeters\n", meters * 100); printf(" %f meters\n", meters); printf(" %f kilometers\n", meters / 1000); return(0); }


[foxtrot]> cc convert.c [foxtrot]> a.out This program will convert inches into the Metric System. Please enter an integer: 356 Conversion of 356 inches into metric yields: 904.240051 centimeters 9.042400 meters 0.009042 kilometers [foxtrot]> a.out This program will convert inches into the Metric System. Please enter an integer: 234567 Conversion of 234567 inches into metric yields: 595800.187500 centimeters 5958.001953 meters 5.958002 kilometers [foxtrot]>