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.
I'm doing these exercises so that I have something to do with C. I didn't use doubles or %.2f because they haven't been taught in chapter 1.
Code:
#include <stdio.h>
main()
{
float Distance,Meters,Feet,Inches,Centimeters;
printf("Enter the distance in Kilometers: ");
scanf("%f",&Distance);
Meters=Distance*1000; //1 km=1000 meters
Feet=Distance*3280.84; //1 km= 3280.84 Feet
Inches=Distance*39370.1; // 1 km= 39370.1 Inches
Centimeters=Distance*100000; //1 km= 100000 Centimeters
printf("%f km/s in:\n\nMeters= \t%f\nFeet= \t\t%f\nInches= \t%f\nCentimeters= \t%f\n",Distance,Meters,Feet,Inches,Centimeters);
return 0;
}
I'm doing these exercises so that I have something to do with C. I didn't use doubles or %.2f because they haven't been taught in chapter 1.
Code:
#include <stdio.h>
main()
{
float Distance,Meters,Feet,Inches,Centimeters;
printf("Enter the distance in Kilometers: ");
scanf("%f",&Distance);
Meters=Distance*1000; //1 km=1000 meters
Feet=Distance*3280.84; //1 km= 3280.84 Feet
Inches=Distance*39370.1; // 1 km= 39370.1 Inches
Centimeters=Distance*100000; //1 km= 100000 Centimeters
printf("%f km/s in:\n\nMeters= \t%f\nFeet= \t\t%f\nInches= \t%f\nCentimeters= \t%f\n",Distance,Meters,Feet,Inches,Centimeters);
return 0;
}
No comments:
Post a Comment