C Exercises: Prints the corresponding value in inches
C Basic Declarations and Expressions: Exercise-54 with Solution
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:

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
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join