C program to enter a distance into kilometre and convert it into meter, feet, inches and centimetre

 GTU PPS Practical-5

Question :

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

Logic :

Logic of this program is very simple as everyone knows the basic mathematics to convert units into each other.
Let's quickly recall the formula of unit conversion.
1 kilometer = 1000 meter
1 kilometer = 3280.84 feet
1 kilometer = 39370.1 inches
1 kilometer = 100000 centimetre
Firstly we have to take distance in kilometer from user. then implement the above formula to convert kilometre into meter, feet, inches and centimetre thereafter Print the converted unites.
Let's look at the algorithm.

Algorithm :

  1. START
  2. Input kilometre.
  3. Compute kilometre into meter, feet, inches and centimetre.
  4. Print meter, feet, inches and centimetre.
  5. ‌STOP

Code:

#include <stdio.h>
int main()
{
float km, m, ft, in, cm;
printf("Enter distance in kilometre:");
scanf("%f", &km);
m = km * 1000;
ft = km * 3280.84;
in = km * 39370.1;
cm = km * 100000;
printf("%.2f kilometre = %.2f metre\n", km, m);
printf("%.2f kilometre = %.2f foot\n", km, ft);
printf("%.2f kilometre = %.2f inches\n", km, in);
printf("%.2f kilometre = %.2f centimetre\n", km, cm);
return 0;
}

Output :

Here you can see output screen of the code. You can get this type of output if you write above code.

c-program-to-enter-distance-into-kilometre-and-convert-it-into-meter-feet-inches-and-centimetre



THANK YOU

Post a Comment

0 Comments