📌  相关文章
📜  程序将厘米转换为米和公里

📅  最后修改于: 2021-04-23 16:05:58             🧑  作者: Mango

给定长度(厘米),任务是将其转换为米和公里。

例子 :

使用的公式:

1m = 100cm
               1km = 100000cm
C++
// C++ program to convert centimeter
// into meter and kilometer
#include 
using namespace std;
int main()
{
    float cm, meter, kilometer;
    cm = 1000;
  
    // Converting centimeter into meter
    // and kilometer
    meter = cm / 100.0;
    kilometer = cm / 100000.0;
  
    cout << "Length in meter = " << meter << "m"
         << "\n";
  
    cout << "Length in Kilometer = " << kilometer << "km"
         << "\n";
  
    return 0;
}


Java
// Java program to convert 
// centimeter into meter 
// and kilometer
import java.io.*;
  
class GFG
{
    public static void main (String[] args) 
    {
        double cm, meter, kilometer;
        cm = 1000;
      
        // Converting centimeter 
        // into meter and kilometer
        meter = cm / 100.0;
        kilometer = cm / 100000.0;
      
        System.out.println("Length in meter = " +
                                    meter + "m");
          
      
        System.out.println("Length in Kilometer = " + 
                                   kilometer + "km");
    }
}
  
// This code is contributed by anuj_67.


Python3
# Python3 program to convert 
# centimeter into meter
# and kilometer
cm = 1000;
  
# Converting centimeter 
# into meter and kilometer
meter = cm / 100.0;
kilometer = cm / 100000.0;
  
# Driver Code
print("Length in meter = " ,
               meter , "m");
print("Length in Kilometer = ", 
             kilometer , "km");
  
# This code is contributed
# by mits


C#
// C# program to convert 
// centimeter into meter 
// and kilometer
using System;
  
class GFG
{
  
// Driver Code
static public void Main ()
{
    double cm, meter, kilometer;
    cm = 1000;
  
    // Converting centimeter 
    // into meter and kilometer
    meter = cm / 100.0;
    kilometer = cm / 100000.0;
  
    Console.WriteLine("Length in " + 
                        "meter = " +
                       meter + "m");
      
  
    Console.WriteLine("Length in " + 
                    "Kilometer = " + 
                  kilometer + "km");
}
}
  
// This code is contributed
// by ajit.


PHP


输出:

Length in meter = 10 m
 Length in kilometer = 0.01 km