How to Convert Km To Meter, Feet, Inch, Cm by C Program

convert distance by C programing language

Introduction:

Converting units of distance is a common task in many scientific and engineering applications. Sometime you have to convert a distance from kilometers to other units such as meters, feet, inches, and centimeters. Using the C programming language, you can convert the distance from kilometer to other units.

In this article, I shall show you how to convert distances from kilometers to meters, feet, inches, and centimeters in C programming language. Here, I create a simple C program that takes a distance (kilometer) as input and convert it in meters, feet, inches, and centimeters.

What is distance :

Distance is a measure of the length between two points. It has no direction. How long a thing or object is situated measure of distance. There are different types of units are used such as kilometers, meters, centimeters, miles, yards, feet, inches etc. In everyday life, you have to convert distance between units.
The measurement of distance is generally used in various fields such as physics, engineering, navigation, construction, sports etc.

The following formulas are used to convert the distance in kilometers into different units (meters, feet, inches, and centimeters).

  • Meter = kilometer X 1000
  • Feet = kilometer X 3280.84
  • Inches = kilometer X 39370.1
  • Centimeter = kilometer X 100000

About the program :

This is a simple C program which converts distances from kilometers to meters, feet, inches and centimeters. In this program, you have to input distance in kilometers. Then, it converts the distance in meters, feet, inches, and centimeters. After that, it displays the output on the console screen.

Explanation of the program :

At first, include stdio.h library in the program. In the main() function, declare five floating point variables (kilometer, meter, feet, inch, centimeter) to store distances in different units. After that, ask the user to enter a distance in kilometers using printf() function. Using scanf() function, store the input value into the “kilometer” variable. Then, calculate the distance in different units from input value.

Finally, display the converted values on the console screen. Here, I print the results to two decimal places with the help of “%.2f” format specifier.

How run the program :

To run this program, you have to install VS Code on your PC. Then, create a C file in it like “convert_distance.c”. Now, copy the below code and paste in the C file you have just created. After saving the file, run the program to see the output.

Source code of the program :

The following code is the source code of converting distances from kilometers to meters, feet, inches, and centimeters in C programming language.

/*Developed by Puskar Jasu*/
#include <stdio.h>
int main()
{
    float kilometer, meter, feet, inch, centimeter;
    printf("Enter distance in Kilometer\n");
    scanf("%f", &kilometer);
    meter = kilometer * 1000;
    feet = kilometer * 3280.84;
    inch = kilometer * 39370.1;
    centimeter = kilometer * 100000;
    printf("%.2f Kilometer = %.2f Meters\n", kilometer, meter);
    printf("%.2f Kilometer = %.2f Feets\n", kilometer, feet);
    printf("%.2f Kilometer = %.2f Inches\n", kilometer, inch);
    printf("%.2f Kilometer = %.2f Centimeters\n", kilometer, centimeter);
    return 0;
}

Output of the program :

After run the program, you can see the following output on your PC.

Output of Convert Km To Meter, Feet, Inch, Cm By C Program

Conclusion :

At last, you have learned how to convert distance in various units in the C programming language. Thank you for visiting my site.

Scroll to Top