In this tutorial, we will write programs in different programming languages to convert inches to centimetres. Inches and centimetres (cm) both are the unit of length.
Inches to Centimetres Formula:
cm = 2.54 * inches
Multiply the value by 2.54.
Java Program
// Java program to convert Inches into cm public class JavaExample { public static void main(String args []) { int inch = 10; double cm; cm = 2.54 * inch; System.out.printf(inch+ " inches = "+cm+ " centimetres"); } }
Output:
10 inches = 25.4 centimetres
In the above program, variable inch
represents the value of length in inches and the variable cm
represents the value in centimetres. The inch is an integer, however the reason why we have declared the variable cm
as double is because, when the inches are multiplied by 2.54, the result contains decimal point.
C Program
#include<stdio.h> int main() { int inch = 5; double cm; cm = 2.54 * inch; printf ("%d inches = %.2f centimetres", inch, cm); return 0; }
Output:
The format specifier %.2f allows to display the output upto two decimal places. You can change this value as per the requirement, for example: if you want to display inches upto three decimal places then use %.3f instead.
C++ Program
// C++ Program to Convert Inches to cm #include <iostream> using namespace std; int main(){ float cm, inches; // User is asked to enter the length value in inches cout << "Enter the length in inches: "; cin >> inches; // converting inches to cm cm = inches * 2.54; // Print length in cm after conversion cout << inches << " inches = " << cm << " cm" << endl; return 0; }
Output:
Enter the length in inches: 10 10 inches = 25.4 cm
Python Program
# Python program to convert length in inches to cm inch=int(input("Enter the length in inches unit:")) # formula to convert length in inches to cm cm = 2.54 * inch; print("The length in cm unit: ",round(cm,2))
Output:
Enter the length in inches unit: 5 The length in cm unit: 12.70
PHP Program
<?php // PHP program for inches to cm conversion $inch = 1; $cm = 2.54 * $inch; echo("1 inches in Centimeter is: " . $cm . "\n"); ?>
Output:
1 inches in Centimeter is: 2.54