Dada la longitud en centímetros, la tarea es convertirla en metros y kilómetros.
Ejemplos:
Entrada: Longitud en centímetros = 1000
Salida:
Longitud en metros = 10 m
Longitud en kilómetros = 0,01 kmEntrada: Longitud en centímetros = 6540
Salida:
Longitud en metros = 65,4 m
Longitud en kilómetros = 0,0654 km
Fórmula a utilizar:
1m = 100cm 1km = 100000cm
C++
// C++ program to convert centimeter // into meter and kilometer #include <bits/stdc++.h> 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
<?php // PHP program to convert // centimeter into meter // and kilometer $cm; $meter; $kilometer; $cm = 1000; // Converting centimeter into // meter and kilometer $meter = $cm / 100.0; $kilometer = $cm / 100000.0; echo "Length in meter = " , $meter ,"m" , "\n"; echo "Length in Kilometer = " , $kilometer , "km" ,"\n"; // This code is contributed by anuj_67. ?>
Javascript
<script> // Javascript program to convert centimeter // into meter and kilometer let cm, meter, kilometer; cm = 1000; // Converting centimeter into meter // and kilometer meter = cm / 100.0; kilometer = cm / 100000.0; document.write("Length in meter = " + meter + "m" + "</br>"); document.write("Length in Kilometer = " + kilometer + "km" + "</br>"); // This code is contributed by jana_sayantan </script>
Producción:
Length in meter = 10 m Length in kilometer = 0.01 km
Complejidad del tiempo: O(1)
complejidad del espacio: O(1)
Publicación traducida automáticamente
Artículo escrito por mansibansal2112 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA