Pages

Sunday, 28 January 2018

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

The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.
* This program takes lenght in kilo-meters from user, converts it into meters,
centimeters, feet and inches and then shows results .*/
#include<stdio.h>
#include<conio.h>
int main ()
{
    /*delaring and initializing variables*/
    float km=0, meter=0, cm=0, feet=0, inch=0;
  
    /*prompt for input*/
    printf("Please enter the distance in 'kilo meters': ");
 
    /*taking length in kilo-meters as input*/
    scanf("%f",&km);
  
    /*calculations*/
    meter = km * 1000;
    cm = meter * 100;
    feet = meter * 3.280839895;
    inch = feet * 12;
  
    /*showing results*/
    printf("Here is the conversion of %f km",km);
    printf("\n\n      In Meters: %f m      \n\n      In Centi Meters: %f cm      \n\n      In Feet: %f feet      \n\n      In inches: %f inch     ",meter,cm,feet,inch);   

    getche();
    return 0;
  
}