Problem 05

author
By Supreme2023-02-14
Problem Statement :
Write a C program to enter a distance in to kilometre and convert it in to meter, feet, inches and centimetre
Code:

#include <stdio.h>

int main()
{

// 5. Write a C program to enter a distance in to kilometre and convert it in to meter,
// feet, inches and centime

printf("\tConvert Kilometer To Other Units");
printf("\n============================================");

float dis;

printf("\n\n Enter The Distance In Kilometer : ");
scanf("%f", &dis);

printf("\n____________________________________________");

printf("\n\n %.2f KM = %.2f Meter ", dis, dis * 1000);

printf("\n\n %.2f KM = %.2f Feet", dis, dis * 3280.84);

printf("\n\n %.2f KM = %.2f Inches", dis, dis * 12 * 3280.84);

printf("\n\n %.2f KM = %.2f Centimeters", dis, dis * 1000 * 100);

printf("\n____________________________________________\n\n");

return 0;
}

Description :
  • This C program prompts the user to input a distance in kilometers and then converts the distance to meters, feet, inches, and centimeters. The program accomplishes this by multiplying the input distance by conversion factors for each unit of measurement.
  • First, the program prints a message to the console informing the user that they will be converting kilometers to other units. Then, the program prompts the user to enter a distance in kilometers using the scanf() function.
  • After the user inputs the distance, the program calculates the corresponding distances in meters, feet, inches, and centimeters using the input distance and conversion factors. The program then prints these converted distances to the console using printf().
  • Finally, the program prints a separator line and returns 0 to indicate successful completion.
Output Image:
Output-image

© Copyright 2022. All right reserved, GTU Coder.