BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Program to Convert Inches to Centimetres

Last Updated: September 13, 2022 by Chaitanya Singh | Filed Under: Programs

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:
Inches to cm - C program 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

Top Related Articles:

  1. Program to Convert Kilometres (km) to Centimetres (cm)
  2. Program to Convert Inches to Feet
  3. Program to Convert Feet to Inches in Java, C, C++, Python & PHP

Tags: Java-Conversion

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap