To convert length in centimeter we know about the relation between centimeter, meter and kilometer.
We have to enter the length in centimeter as input and we convert it to the meter and kilometer. So, let's get started.
Knowledge Required
As for any program we must know the approach how to solve and what the knowledge required.
So, the required knowledge to convert centimeter into meter and kilometer are as follows:
First, relation between centimeter and meter:
1 meter = 100 cm
Therefore,
Divide the value by 100 , we get
1 centimeter = 0.01 meterSecond, relation between centimeter and kilometer
1 kilometer = 1000 meter = 1,00,000 centimeter
Therefore,
Divide the value by 100000 , we get
1 centimeter = 0.000001 kilometer
Logic to solve code
1. Take value of centimeter as input
2. Perform the Operation as above explained
3. Finally print the values
Full Code to find the value in meter and kilometer from centimeter
/*
Program to convert centimeter into meter and kilometer
*/
#include<stdio.h>
int main()
{
float cmeter, meter, kmeter;
// take the value of centimeter from user
printf("Enter the value in centimeter\n");
scanf("%f",&cmeter);
// Now Perform the program
meter = cmeter / 100;
// this gives value in meter
//Now perform kilometer program
kmeter = cmeter / 100000;
// this gives value in kilometer
//Now print all the values
printf("Value in meter = %.4f\n",meter);
printf("Value in kilometer = %.8f",kmeter);
return 0;
}
\n is an escape sequence used to change the line;
%.5f means it takes values after decimal point by five.
We hope you will be able to understand the above code how to convert value in centimeter to the meter and kilometer. I wish you to please write this code on your own and run and see the result every time and looks your answer and you are always welcome to comment your answer in the comment box.
So, What's Your Answer! Write Here Below in the comment box!
0 Comments