Q: 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.

#include<stdio.h>
int main()

{
    float km, m, cm, f, in;     /*km=Kilometers,m=Meters,cm=Centimeters,f=Feet,in=Inch*

    printf("Enter distance in kilometers: ");

    scanf("%f", &km);

    /* formulae for distance conversion */
    m = km * 1000;
    cm = km * 1000 * 100;
    f = km * 3280.84;
    in = km * 39370.08;

    printf("\nThe distance in Feet: %f\n", f);
    printf("The distance in Inches: %f\n", in);
    printf("The distance in Meters: %f\n", m);
    printf("The distance in Centimeters: %f\n", cm);

    return 0;
}


----------------------------------------
output:

Enter distance in kilometers: 5

The distance in Feet: 16404.199219
The distance in Inches: 196850.406250
The distance in Meters: 5000.000000
The distance in Centimeters: 500000.000000



Comments

Popular posts from this blog

Q: The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate area & perimeter of the rectangle and area & circumference of the circle.

Q: If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. (Hint: Use the modulus operator ‘%’)