[Tutorial 7] 14.Write a program that converts inches to centimeters. For example, if the user enters 16.9 for a Length in inches, the output would be 42.926cm. (Hint: 1 inch = 2.54 centimeters.)
#include <stdio.h>
int main()
/*Input length in inches from the user*/
printf("Enter length in inches: ");
scanf("%f", &inches);
/*Convert inches to centimeters*/
centimeters = inches * 2.54;
/* Display the result */
printf("%.2f inches is equal to %.3f centimeters\n", inches, centimeters);
int main()
{
float inches, centimeters;
float inches, centimeters;
/*Input length in inches from the user*/
printf("Enter length in inches: ");
scanf("%f", &inches);
/*Convert inches to centimeters*/
centimeters = inches * 2.54;
/* Display the result */
printf("%.2f inches is equal to %.3f centimeters\n", inches, centimeters);
return 0;
}
}
This C program efficiently converts a length in inches inputted by the user into centimeters using the conversion factor of 1 inch equal to 2.54 centimeters. By taking user input, performing a simple multiplication based on the conversion factor, and then displaying the converted length in centimeters, the program offers a straightforward and practical tool for length conversion, facilitating quick and accurate calculations in a single execution.
Comments
Post a Comment