Convert km to m,feet,inch and cm in C

Today, I am back with one more program to convert km to m,feet,inch and cm in C language. This is the second program of [I] section of Chapter 1:Getting Started of the book, “Let us C” by “Yashwant Kanetkar”.  If you are unsure about any part and more information, put it down in the comments section below or look it up on Google if you want a quick response.  We will try to get back to you as soon as we see the comment. Share it with your friends as it might be helpful to them as well.

Question:

The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in metres, feet, inches and centimetres.

Solution to convert km to m,feet,inch and cm in C

This problem is similar to the previous problem, Calculate gross salary in C. Here, we just have to input the distance between two cities in kilometers. Let’s create a variable named “km” and store the value inputted using scanf() function. Then, using respective variables for meters, feet, inch and centimeters, convert the “km” variable into the respective metric and print the output. I have used the variables ‘m’,’feet’,’inch’ and ‘cm’ for meters, feet, inches and centimeters respectively. Then store the formulas into their respective variables and print the output.

Pro Tip: Now you can remotely catch up with your programming work on your windows based iOS emulators from anywhere on any device(PC/android/iOS) by loading them into cloud with high performance citrix vdi from CloudDesktopOnline.com. If you prefer a dedicated server with 100% high performance, Rent a dedicated server from Apps4Rent.com with 24*7*365 days top-notch technical support & migration assistance.

Download the source code:

Download Program

Program to convert km to m,feet,inch and cm in C

#include<stdio.h>
#include<conio.h>

void main(){
float km,m,feet,inch,cm;
printf("Enter the distance between two cities(in km) - ");
scanf("%f",&km);
m = km*1000; //since 1km = 1000m
feet= km*3280.84; //since 1km=3280.84feet
inch=km*39370.1; //since 1 km=39370.1inches
cm=km*100000; //since 1km = 100000cm
printf("\nDistance in kilometres = %f ",km);
printf("\nDistance in metres = %f ",m);
printf("\nDistance in feet = %f ",feet);
printf("\nDistance in inches = %f ",inch);
printf("\nDistance in centimetres = %f ",cm);
getch();
}

Output:

Enter the distance between two cities(in km) – 20
Distance in kilometres = 20.000000
Distance in metres = 20000.000000
Distance in feet = 65616.796875
Distance in inches = 787402.000000
Distance in centimetres = 2000000.000000

Download the source code:

Download Program

See Also:

Calculate gross salary in C

Introduction to C Programming

Adding two numbers in C

Subtracting two numbers in C

cc programminghow tokm to cmkm to feetkm to inchkm to m
Comments (0)
Add Comment