THIS PROGRAM IS WRITTEN IN C
/* Program to convert length to different units*/
#include
int main(void)
{
float length, converted, measure;
char inUnits, outUnits;
printf("Enter the value of length to be converted: ");
scanf("%f", &measure);
printf("Enter the unit of value entered (I, F, Y, or M): ");
scanf("%c", &inUnits);
printf("Enter the unit to convert value to (c, m, or k): ");
scanf("%c", &outUnits);
switch(inUnits){
case 'I':
converted = measure * 2.54001;
printf("The length you entered in inches is equal to %f centimeters", converted);
break;
case 'Y':
converted = measure * 0.9144402;
printf("The length you entered in yards is equal to %f meters", converted);
break;
case 'M':
converted = measure * 1.60935;
printf("The length you entered in miles is equal to %f kilometers", converted);
break;
case 'F':
switch(outUnits){
case 'c':
converted = measure * 30.4801;
printf("The length you entered in feet is equal to %f centimeters", converted);
break;
case 'm':
converted = measure * 0.304801;
printf("The length you entered in feet is equal to %fmeters", converted);
break;
default:
printf("Incorrect unit entered. Please enter a valid unit.");
break;}
break;
default:
printf("Incorrect unit entered. Please enter a valid unit.");
break;}
return 0;
}
Faq
Information Technology Hub
Comments