UNIT CONVERSION PROGRAM
UNIT CONVERSION PROGRAM
INPUT
#include <stdio.h>
float kgtomiles(float number)
{
return (number * 0.62);
}
float inchestofoot(float number)
{
return (number * 0.083);
}
float cmtoinches(float number)
{
return (number * 0.39);
}
float poundtokgs(float number)
{
return (number * 0.45);
}
float inchestometers(float number)
{
return (number * 0.02);
}
int main()
{
int conversion;
float num;
char type;
printf("Enter\n 1 if you want to convert kg to miles\n 2 if you want to convert inches to foot\n 3 if you want to convert cm to inches\n 4 if you want to convert pound to kgs\n 5 if you want to convert inches to meters\n ");
scanf("%d", &conversion);
switch (conversion)
{
case 1:
printf("You have chosen kms into miles\n");
printf("Enter the number you want to convert :-\n");
scanf("%f\n", &num);
printf("The result is %f miles\n", kgtomiles(num));
break;
case 2:
printf("You have chosen inches into foot \n");
printf("Enter the number you want to convert :-\n");
scanf("%f\n", &num);
printf("The result is %f miles\n", inchestofoot(num));
break;
case 3:
printf("You have chosen cm into inches\n");
printf("Enter the number you want to convert :-\n");
scanf("%f\n", &num);
printf("The result is %f miles\n", cmtoinches(num));
break;
case 4:
printf("You have chosen pound to kgs\n");
printf("Enter the number you want to convert :-\n");
scanf("%f\n", &num);
printf("The result is %f miles\n", poundtokgs(num));
break;
case 5:
printf("You have chosen inches into meters\n");
printf("Enter the number you want to convert :-\n");
scanf("%f\n", &num);
printf("The result is %f miles\n", inchestometers(num));
break;
}
return 0;
}
OUTPUT
Enter
1 if you want to convert kg to miles
2 if you want to convert inches to foot
3 if you want to convert cm to inches
4 if you want to convert pound to kgs
5 if you want to convert inches to meters
2
You have chosen inches into foot
Enter the number you want to convert :-
2
The result is 0.166000 miles
Comments
Post a Comment