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

  • Home
  • DS & Algo. ▾
    • Data Structure
    • Algorithms
    • Coding Problems
  • Languages ▾
    • C
    • C++
    • C++ STL
    • Java
    • Python
    • Scala
    • Ruby
    • C#.Net
    • Golang
    • Android
    • Kotlin
    • SQL
  • Web. ▾
    • JavaScript
    • CSS
    • jQuery
    • PHP
    • Node.Js
    • AdonisJs
    • VueJS
    • Ajax
    • HTML
    • Django
  • Programs ▾
    • C
    • C++
    • Data Structure
    • Java
    • C#.Net
    • VB.Net
    • Python
    • PHP
    • Golang
    • Scala
    • Swift
    • Rust
    • Ruby
    • Kotlin
    • C Interview Programs
  • Aptitude ▾
    • C Aptitude
    • C++ Aptitude
    • Java Aptitude
    • C# Aptitude
    • PHP Aptitude
    • Linux Aptitude
    • DBMS Aptitude
    • Networking Aptitude
    • AI Aptitude
    • More...
  • Interview ▾
    • Golang
    • MIS Executive
    • DBMS
    • C
    • Embedded C
    • Java
    • SEO
    • HR
  • Find Output ▾
    • C
    • C++
    • C#.Net
    • Java
    • Go
    • PHP
    • More...
  • MCQs ▾
    • Web Technologie MCQs
    • CS Subjects MCQs
    • Databases MCQs
    • Programming MCQs
    • Testing Software MCQs
    • Digital Mktg Subjects MCQs
    • Cloud Computing S/W MCQs
    • Engineering Subjects MCQs
    • Commerce MCQs
    • More MCQs...
  • CS Subjects ▾
    • Machine Learning/AI
    • Operating System
    • Computer Network
    • Software Engineering
    • Discrete Mathematics
    • Digital Electronics
    • Data Mining
    • MIS
    • DBMS
    • Embedded Systems
    • Cryptography
    • CS Fundamental
    • More Tutorials...
  • More ▾
    • Tech Articles
    • Puzzles
    • Full Forms
    • Code Examples
    • Blogs
    • Guest Post
    • Programmer's Calculator
    • XML Sitemap Generator
    • About
    • Contact

Home »C solved programs »C basic programs

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

Problem statement

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.

Example

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): 500Meter = 500000.000000Feet = 1640420.000000Inches = 19685050.000000 Centimeters = 50000000.000000Second run:Enter the distance between Gwalior and Delhi (in KM): 6Meter = 6000.000000Feet = 19685.039062Inches = 236220.593750 Centimeters = 600000.000000Third run:Enter the distance between Gwalior and Delhi (in KM): 1Meter = 1000.000000Feet = 3280.840088 Inches = 39370.101562Centimeters = 100000.000000 

C Basic Programs »

C program to calculate profit or loss

C program to find area and perimeter of the rectangle

Related Programs

  • C program to find subtraction of two integer number
  • C program to find sum and average of two numbers
  • C program to print ASCII value of a character
  • C program to find cube of an integer number using two different methods
  • C program to find quotient and remainder
  • Program to calculate simple interest
  • Program to check whether number is EVEN or ODD
  • Program to find largest number among three numbers
  • C program to check whether a person is eligible for voting or not?
  • C program to read marks and print percentage and division
  • Program to find gross salary of an employee
  • C program to convert temperature from Fahrenheit to Celsius and vice versa
  • C program to calculate X^N (X to the power of N) using pow function
  • C program to find the difference of two numbers
  • C program to print size of variables using sizeof() operator
  • C program to demonstrate examples of escape sequences
  • C program to find area and perimeter of circle
  • C program to find area of a rectangle
  • C program to calculate HCF of two numbers
  • C program to multiply two numbers using plus operator
  • C program to demonstrate example of global and local scope
  • C program to demonstrate example of floor and ceil functions
  • Write a C program to evaluate the net salary of an employee given the following constraints
  • How to swap two numbers without using a temporary variable using C program?
  • C program to read name and marital status of a girl and print her name with Miss or Mrs
  • C program to check given number is divisible by A and B
  • C program to find sum of all numbers from 0 to N without using loop
  • Input hexadecimal value in C language
  • Printing an address of a variable in C
  • printf() statement within another printf() statement in C
  • printf() examples/variations in C
  • C program to calculate profit or loss
  • Calculate the distance between two cities from kilometers to meters, centimeters, feet and inches using C program
  • C program to find area and perimeter of the rectangle
  • C program to generate random numbers within a range
  • C Example to subtract two integers without using Minus (-) operator
  • C Example for different floating point values prediction
  • C Example for nested 'printf'
  • C program to get remainder without using % operator
  • C program to convert ascii to integer (atoi implementation)
  • C program to print ASCII table
  • C program to swap two numbers using four different methods
  • C program to check a given character is alphanumeric or not without using the library function
  • C program to check a given character is a digit or not without using the library function
  • C program to check a given character is a whitespace character or not without using the library function
  • C program to check a given character is an uppercase character or not without using the library function
  • C program to check a given character is a lowercase character or not without using the library function
  • C program to check a given character is a punctuation mark or not without using the library function
  • C program to check whether a character is a printable character or not without using library function
  • C program to convert a lowercase character into uppercase without using library function
  • C program to convert an uppercase character into lowercase without using library function
  • C program to print all punctuation marks without using library function
  • C program to print all punctuation marks using the ispunct() function
  • C program to print all printable characters using the isprint() function
  • C program to print all printable characters without using the library function
  • C program to make a beep sound
  • C program to convert a given number of days into days, weeks, and years
  • C program to find the roots of a quadratic equation
  • C program to find the GCD (Greatest Common Divisor) of two integers
  • C program to find the LCM (Lowest Common Multiple) of two integers
  • C program to calculate the area of a triangle given three sides
  • C program to calculate the area of a triangle given base and height
  • C program to calculate the area of Trapezium
  • C program to calculate the area of the rhombus
  • C program to calculate the area of Parallelogram
  • C program to calculate the area of Cube
  • C program to calculate the volume of Cube
  • C program to find the Surface Area and Volume of the Cylinder
  • C program to calculate the surface area, volume, and space diagonal of cuboids
  • C program to calculate the surface area, volume of Cone
  • C program to calculate the surface area, volume of the Sphere
  • C program to calculate the mean, variance, and standard deviation of real numbers
  • C program to read coordinate points and determine its quadrant
  • C program to calculate the value of nCr
  • C program to calculate the value of nPr
  • C program to calculate the product of two binary numbers
  • C program to calculate the addition of two complex numbers
  • C program to extract the last two digits from a given year
  • C program to perform the ATM Transactions
  • C program to read the height of a person and the print person is taller, dwarf, or average height person
  • C program to read the grade of student print equivalent description

Comments and Discussions!

Load comments ↻


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

FAQs

How do you calculate the distance between two points using structure in C? ›

Inside the function, we calculate the differences in the x and y coordinates of the two points using subtraction. We then apply the Euclidean distance formula by squaring the differences, adding them together, and taking the square root. The calculated distance is returned as a double value.

How is distance between two cities measured? ›

Distance between cities or 2 locations is measured in either kilometer, or miles, or nautical miles.

How to convert cm to inches in C program? ›

Program 1: Write a Program in C for converting the cm to feet and inches.
  1. #include<stdio.h> int main() { int centimeter = 40; double inch, feet; inch = 0.3937 * centimeter; feet = 0.0328 * centimeter; printf ("Inches is: %.2f \n", inch); printf ("Feet is: %.2f", feet); return 0; }
  2. <?

What is the distance formula in C? ›

gdistance = ((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)): This formula computes the square of the distance between the points.

How do you convert 2 km to cm? ›

Kilo in kilometer stands for 1000 ,
  1. hence 1 kilometer means 1000 meters.
  2. and 2 kilometers means 2×1000=2000 meters.
  3. Therefore 2000 meters are 2000×100=200,000 centimeters.
  4. Hence, there are 200,000 centimeters in 2 kilometers.
Nov 14, 2016

What is the distance between cm and km? ›

As we know, 1 centimeter is equal to 1/100000 kilometer. i.e. 1 cm = 0.00001 km. Thus, to convert cm to km, multiply the number of cm by 0.00001. In other words, divide the number of cm by 100000 to get the value in km.

Is the distance between two cities measured in kilometers? ›

The distance between two cities can be very large. Since kilometre is a bigger unit of distance, the distance between two cities is measured in kilometres.

What is the best estimate of measure in distance between two cities? ›

We use kilometers to measure distances from one place to another. And it takes about 10 minutes to walk one kilometer. So this is the best unit of measurement to use to measure the distance between two cities.

What is 7 cm long? ›

Therefore, 7 centimeters is approximately 2.76 inches.

What is 150 by 200 cm in inches? ›

150 cm × 200 cm (60 in × 79 in)

How do you convert inches to cm in C? ›

It is used in the International System of Units, which is the current form of the metric system. Here, the C program solves the problem by taking the input value in inches and using standard formulas to convert it into centimeters. => 1 Inch = 2.54 Centimeters. => 1 Centimeter = 0.393701 inches.

How do you calculate the distance between two points using structure? ›

The distance between two points can be calculated using the following steps, Denote the given points as (x1, y1) and (x2, y2). Apply the Euclidean distance formula, distance, d = √[(x2 − x1)2 + (y2 − y1)2]

What's the formula for distance between two points? ›

Distance between two points is the length of the line segment that connects the two points in a plane. The formula to find the distance between the two points is usually given by d=√((x2 – x1)² + (y2 – y1)²).

What is the formula for Euclidean distance in C? ›

The formula for Euclidean distance in two dimensions is D = ( x 2 − x 1 ) 2 + ( y 2 − y 1 ) 2 , where D is the Euclidean distance, and ( x 1 , y 1 ) and ( x 2 , y 2 ) are the Cartesian coordinates of the two points.

Top Articles
Latest Posts
Article information

Author: Fredrick Kertzmann

Last Updated:

Views: 5536

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Fredrick Kertzmann

Birthday: 2000-04-29

Address: Apt. 203 613 Huels Gateway, Ralphtown, LA 40204

Phone: +2135150832870

Job: Regional Design Producer

Hobby: Nordic skating, Lacemaking, Mountain biking, Rowing, Gardening, Water sports, role-playing games

Introduction: My name is Fredrick Kertzmann, I am a gleaming, encouraging, inexpensive, thankful, tender, quaint, precious person who loves writing and wants to share my knowledge and understanding with you.