In this tutorial you will learn about the C Program to Convert Centimeter to Meter and Kilometer and its application with practical example.
C Program to convert Centimeter to Meter and Kilometer
In this tutorial, we will learn to create a C program that will convert Centimeter to Meter and Kilometer in C programming.
Prerequisites
Before starting with this tutorial, we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C Programming.
- Arithmetic Operators in C Programming.
What are Centimeter, Meter and Kilometer?
The Centimeter, Meter, and Kilometer are the metric units for the measurement of length between two points.
Description Table below.
1 2 3 4 5 |
<strong>1. 10 Millimeters is equal to 1 Centimeters. 2. 1 Meter is equal to 100 Centimeters. 3. 1 kilometer is equal to 1,000 Meters.</strong> |
Algorithm:-
1 2 3 4 5 6 7 8 9 10 11 |
1. Declaring the variable for taking the input from the user. 2. Taking the input of centimeters from the user. 3. Passing that centimeters to program code to convert. 4. Converting the units in the bigger units. 5. Printing the converted values. 6. End Program. |
Program to Convert Centimeters to meters and Kilometer.
In today’s program, we will first take the input from the user in centimeters. And then we will convert that input into meters, kilometers using a small program. Using the above table conversion values.
With the help of the below program, we can convert the centimeters to bigger units.
Program Code:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/* C Program to Convert Centimeters to Meter and Kilometer */ #include <stdio.h> int main() { //Declaring the variable required for the program float cm, m, km; /* Input length in centimeter from user for the conversion */ printf("Enter length in centimeter: "); scanf("%f", &cm); /* Convert centimeter into meter and kilometer */ m = cm / 100.0; km = cm / 100000.0; //Printing the converted meters values to the user printf("Length in Meter = %.2f m \n", m); //Printing the converted kilometers values to the user printf("Length in Kilometer = %.2f km", km); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- cm = it will store the input centimeters value.
Taking the input from the user in centimeters.
Converting into bigger values.
Printing the output of the program.