C Exercises: Prints the corresponding value in inches
Convert distance from centimeters to inches
Write a C program that accepts a distance in centimeters and prints the corresponding value in inches.
Note: 1 inch = 2.54 cm.
Pictorial Presentation:

Sample Solution:
C Code:
#include <stdio.h>
// Define a constant for converting inches to centimeters
#define INCH_TO_CM 2.54
int main() {
double inch, cm;
// Prompt user to input the distance in centimeters
printf("Input the distance in cm:\n");
scanf("%lf", &cm);
// Convert centimeters to inches
inch = cm / INCH_TO_CM;
// Display the converted distance
printf("Distance of %0.2lf cms is = %0.2lf inches\n", cm, inch);
return 0;
}
Sample Output:
Input Data: 500cms Input the distance in cm: Distance of 500.00 cms is = 196.85 inches
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to convert a distance from inches to centimeters with precision up to three decimals.
- Write a C program to convert a list of distances in centimeters to inches using dynamic memory allocation.
- Write a C program to convert a distance in centimeters to both feet and inches.
- Write a C program to accept a distance in centimeters and output its equivalent in inches and meters.
C programming Code Editor:
Previous: Write a C program that accepts a distance in centimeters and prints the corresponding value in inches.
Next: Write a C program that swaps two numbers without using third variable.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics