Friday 28 March 2014

7

C Program 4: To Convert distance in Km to cm, feet, inch and meter.

  • Friday 28 March 2014
  • IndianBooktuber
  • Share
  • Aim: 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.
    Theory: This program needs no complex coding. It's a simple program where you need to know four basic mathematical formulae. Once you know them, you can easily code this program in C.
    Here's the code:

    //to convert distance from km to m, cm, feet and inches
    #include<stdio.h>
    #include<conio.h>
    int main()
    {
        float km, m, cm, feet, inch;
        printf("Enter the distance in kilometers: ");
        scanf("%f", &km);
        m=km*1000;
        cm=m*100;
        feet=km*3280.8;
        inch=feet*12;
        printf("The distance in meters is %f\n", m);
        printf("The distance in centimeters is %f\n", cm);
        printf("The distance in feet is %f\n", feet);
        printf("The distance in inches is %f\n", inch);
        getch();
        return 0;
    }


    We used four formulae in the code and calculated the values and then printed the result. That's all. It's too easy. Isn't it?
    Here's the snapshot of output:

    7 Responses to “C Program 4: To Convert distance in Km to cm, feet, inch and meter.”

    PrathmeshMalviya said...
    15 August 2018 at 23:27

    thanks dear


    Unknown said...
    13 October 2018 at 08:29

    when I tried same program , it is returning 0 as output


    Unknown said...
    7 August 2019 at 08:52

    THANKS


    Unknown said...
    1 October 2019 at 12:23

    Thanks you so much


    Unknown said...
    22 January 2020 at 23:38

    Thanks,my mistake is I was adding the HF math.h


    Codewin said...
    12 April 2020 at 09:50

    Thank you so much


    Codewin said...
    12 April 2020 at 09:50

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


    Post a Comment

    Subscribe