C Program to convert distance in meters, feet, inches, and centimeters
Posted in: C Language

C Program to convert distance in meters, feet, inches, and centimeters

In this c program, we will convert distance input by the user in meters, feet, inches, and centimeters. We will also write the algorithm of c program to convert distance in meters, feet, inches, and centimeters. We will firstly breakdown the problem and write an algorithm, then after that, we will write the c program and obtain the required output.

We need to take distance (in kilometers) from the user in kilometers and then convert it into meters, feet, inches, and centimeters and display as an output on the screen.

This tutorial is broke down in following parts:

  1. Concepts
  2. Algorithm
  3. Program
  4. Output
  5. Resources

Let’s write this c program to convert distance in meters, feet, inches and centimeters. But before that, let’s understand all the concept that we are gonna use in our program.

1. Concepts

So, we have the distance in kilometers that is input by the user and we need to display it in meters, feet, inches, and centimeters through a c program, and display them separately on the output screen.

Formula of the calculations:

Meter = km * 1000
Feet = km * 3280.84
Inches = km * 39370.1
Centimeter = km * 100000

What are the concept of c programming you need to learn before writing this program?

  1. scanf() function
  2. Operators
  3. printf() function

Kindly, learn these basic topics, before continuing and writing this C Program.

2. Algorithm

Here’s the algorithm of writing this C Program to convert distance in meters, feet, inches, and centimeters:

  1. START
  2. INPUT DISTANCE
  3. Meter = km * 1000
  4. Feet = km * 3280.84
  5. Inches = km * 39370.1
  6. Centimeter = km * 100000
  7. DISPLAY Meter
  8. DISPLAY Feet
  9. DISPLAY Inches
  10. DISPLAY Centimeter
  11. STOP

Follow the same algorithm and let’s write the actual c program.

3. C Program to convert distance in meters, feet, inches and centimeters

/* C Program to convert input distance in meter, feet, inches, centimeter */ #include <stdio.h>
#include <conio.h>

int main() {
int distance;
float meter, feet, inches, centimeter;

printf("Enter the distance [in Kilometers]: ");
scanf("%d", & distance);

meter = distance * 1000;
feet = distance * 3280.84;
inches = distance * 39370.1;
centimeter = distance * 100000;

printf("Meter = %f\n", meter);
printf("Feet = %f\n", feet);
printf("Inches = %f\n", inches);
printf("Centimeters = %f\n", centimeter);

getch();
}

4. Output

As we have written out C Program, let’s have a look at the out. We are giving input distance as 520 in kilometers and now, here are the outputs.

c program to convert distance in meters, feet, inches, and centimeters
Output from Repl.it – Online C IDE

5. Resources

Here are the files of the program, you can download and try it out on your computer:

  1. Raw Code
  2. C Program File

Read next: Write a program in C to input and add two matrix