Saturday, January 30, 2010

CHAP 1[H]b Converting distance in km to m,inches,cm

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.

void main()
{
float distance,distancem,distancefeet,distanceinches,distancecm;
printf("\nInput distance in km");
scanf("%f",&distance);
distancem= distance*1000.0;
distancefeet= distancem*3.2808;
distanceinches= (distance*100000.0)/2.54;
distancecm = distance*100000.0;
printf("\n Distance in metres = %fm\n Distance in feet = %fft\n Distance in inches = %finches\n Distance in cm = %fcm",distancem,distancefeet,distanceinches,distancecm);
}

1 comment: