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 Kilometres (km) to Centimetres (cm)

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

In this guide, we will see programs to convert Kilometres to Centimetres in various programming languages such as Java, C, C++, Python, PHP. The kilometres and centimetres both are the unit of lengths.

Formula to convert Kilometres to Centimetres

cm = km * 100000

Multiply the km by 100000 to get the length in cm.

Input: .5 km
Output: 50000 cm

Java Program

// Java program to convert length given in Kilometres into centimetres
class JavaExample { 
  public static void main(String args []) 
  { 
    double km = 2; 
    double cm; 
    cm = 100000 * km; 
    System.out.println(km+ "km = "+cm+" cm"); 
  } 
}

Output:

2.0km = 200000.0 cm

C Program

#include<stdio.h>
int main()
{
  double km = 3, cm;

  //kilometres to centimetres conversion
  cm = 100000 * km;

  printf ("3 kilometres = %.2f centimetres", cm);

  return 0;
}

Output:

3 kilometres = 300000.00 centimetres

C++ Program

// C++ Program to Convert kilometres to centimetres
#include <iostream>
using namespace std;

int main(){
  double km, cm;

  // User is asked to enter the length in kilometres
  cout << "Enter the length in kilometres: ";
  cin >> km;

  // converting length from km to cm
  cm = km * 100000;

  // displaying length in centimetres
  cout << "The length in centimetre is: " << cm;
  return 0;
}

Output:

Enter the length in kilometres: 1.5
The length in centimetre is: 150000

Python Program

# Python program to convert length given in km to cm

km = float(input("Enter the length in kilometres: "))

# convert km to cm by multiplying the value in km by 100000
cm = 100000 * km;

print("The length in centimetre is: ",round(cm,3))

Output:

Enter the length in kilometres: .25
The length in centimetre is:  25000.0

PHP Program

<?php 
// PHP program for kilometres to centimetres conversion 
$km = 5.5; //length in kilometres
$cm = 100000 * $km; //conversion from km to cm
echo("The length in centimetres is: " . $cm); 
?> 

Output:

The length in centimetres is: 550000

Recommended Posts

  • Program to Convert Inches to Centimetres
  • Program to Convert Inches to Feet

Top Related Articles:

  1. Program to Convert Inches to Feet
  2. Program to Convert Inches to Centimetres
  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