Home » C solved programs » C basic programs

# Calculate the distance between two cities from kilometers to meters, centimeters, feet and inches using C program

**Calculating the distance in C**: Here, we are implementing a C program that will input **distance between two cities in kilometers and print the distance in meters, feet, and inches**.

Submitted by Manju Tomar, on August 01, 2019

Input the **distance between two cities in kilometers**, we have to **calculate the distance in meters, feet, and inches**.

In the below program, we are taking input of the distance between two cities in kilometers and converting them into meters, centimeters, feet, and inches.

For Example: If there are two cities "Gwalior" and "Delhi", their distance is 500 kilometers, after converting the distance from a kilometer, the distance value will be: 500000 meters, 1640420 feet, 19685050 inches, and 50000000 centimeters.

**Here are the formulas:**

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

## C program to convert distance from km to meters, feet, inches, and, centimeters

/* calculate the distance in meter, feet, inches and centimeter */ #include <stdio.h> int main() { /*Declare the variables*/ int distance; float meter; float feet; float inches; float centimeter; /*input the value of distance through the keyboard*/ printf("Enter the distance between Gwalior and Delhi (in KM): "); scanf("%d", &distance); /* converting the distance into meters, feet, inches, and, centimeter */ meter = distance * 1000; feet = distance * 3280.84; inches = distance * 39370.1; centimeter = distance * 100000; /*printing the results*/ printf("Meter = %f\n", meter); printf("Feet = %f\n", feet); printf("Inches = %f\n", inches); printf("Centimeters = %f\n", centimeter); return 0; }

**Output**

First run: Enter the distance between Gwalior and Delhi (in KM): 500 Meter = 500000.000000 Feet = 1640420.000000 Inches = 19685050.000000 Centimeters = 50000000.000000 Second run: Enter the distance between Gwalior and Delhi (in KM): 6 Meter = 6000.000000 Feet = 19685.039062 Inches = 236220.593750 Centimeters = 600000.000000 Third run: Enter the distance between Gwalior and Delhi (in KM): 1 Meter = 1000.000000 Feet = 3280.840088 Inches = 39370.101562 Centimeters = 100000.000000

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.