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

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

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

This tutorial is broken down in following parts:

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

Let’s write this c program to convert distance into meters, feet, inches, and centimeters. But before that, let’s understand all the concepts 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 to calculate the distance into different units:

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?

  • scanf() function
  • Operators
  • printf() function

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

2. Algorithm

Here’s the algorithm for writing this C Program to convert distance into 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 into meters, feet, inches, and centimeters

Here’s the C Program to convert distance into meters, feet, inches, and centimeters:

/* C Program to convert 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 the input distance as 520 kilometers and now, here are the outputs.

groot
groot

Leave a Reply

Your email address will not be published. Required fields are marked *