C++ program to enter the length in centimeter and convert it into meter and kilometer
ADVERTISEMENTS
C++ program to enter the length in centimeters and convert it into meters and kilometers.
There are you will learn how to convert the centimeter into meter and kilometer in the C++ language.
Formula:
1m = 100cm
1km = 100000cm
Let us understand this example through the C++ program:
// C++ program to convert centimeter into meter and kilometer
#include <iostream>
using namespace std;
int main() {
float c, m, k;
// c = centimeter
// m = meter
// k = kilometer
cout << "Enter the length in centimeter::\n";
cin >> c;
/* Convert centimeter into meter and kilometer */
m = (float)(c / 100);
k = (float)(c / 100000);
// Output
cout << "\nLength in Meter = " << m << " meter \n";
cout << "Length in Kilometer = " << k << " kilometer\n";
return 0;
}
Output:
Enter the length in centimeter::
100
Length in Meter = 1 meter
Length in Kilometer = 0.001 kilometer