将厘米转换为米和千米的 C++ 程序
给定输入长度单位为厘米,任务是将给定的长度转换为米和千米
我们可以使用长度转换公式来完成此操作 -
1 m = 100 cm 1 km = 100000 cm
示例
Input-: centimetre = 100 Output -: Length in meter = 3m Length in Kilometer = 0.003km
算法
Start Step 1 -> Declare variables as centimetre, meter, kilometre Step 2 -> set centimetre=100 Step 3 -> Set meter = centimeter / 100.0 Step 4 -> Set kilometer = centimeter / 100000.0 Step 5 -> print meter and kilometer Stop
示例
#include <bits/stdc++.h> using namespace std; int main(){ float centimeter, meter, kilometer; centimeter = 300; // Converting centimeter into meter and kilometer meter = centimeter / 100.0; kilometer = centimeter / 100000.0; cout << "Length in meter = " << meter << "m" <<endl; cout << "Length in Kilometer = " << kilometer << "km"<<endl; return 0; }
输出
Length in meter = 3m Length in Kilometer = 0.003km
广告