Q. Write a C program to convert Meter to Inch and Inch to Meter.
Ans.
keep in mind:
1 Meter = 39.37 Inch
1 Inch = 0.025 Meter
/*c program for convert meter to inch and vice-versa*/
#include<stdio.h>
int main()
{
int ch;
double meter,inch;
printf("\nEnter 1 for convert Meter to Inch.");
printf("\nEnter 2 for convert Inch to Meter.");
printf("\nEnter 0 for exit.");
printf("\n\nEnter your choice : ");
scanf("%d", &ch);
switch(ch)
{
case 1:
printf("\nEnter value in Meter: ");
scanf("%lf", &meter);
inch = (39.37) * meter;
printf("\n\t-- Convert Meter to Inch --\n");
printf("\n%lf meter = %lf Inch",meter,inch);
break;
case 2:
printf("\nEnter value in Inch: ");
scanf("%lf", &inch);
meter = (.025) * inch;
printf("\n\t-- Convert Inch to meter --\n");
printf("\n%lf Inch = %lf Meter",inch,meter);
break;
case 0:
goto exit;
default:
printf("\nYou enter invalid options.");
}
exit:
return 0;
}
The output of above program would be:
Ans.
keep in mind:
1 Meter = 39.37 Inch
1 Inch = 0.025 Meter
/*c program for convert meter to inch and vice-versa*/
#include<stdio.h>
int main()
{
int ch;
double meter,inch;
printf("\nEnter 1 for convert Meter to Inch.");
printf("\nEnter 2 for convert Inch to Meter.");
printf("\nEnter 0 for exit.");
printf("\n\nEnter your choice : ");
scanf("%d", &ch);
switch(ch)
{
case 1:
printf("\nEnter value in Meter: ");
scanf("%lf", &meter);
inch = (39.37) * meter;
printf("\n\t-- Convert Meter to Inch --\n");
printf("\n%lf meter = %lf Inch",meter,inch);
break;
case 2:
printf("\nEnter value in Inch: ");
scanf("%lf", &inch);
meter = (.025) * inch;
printf("\n\t-- Convert Inch to meter --\n");
printf("\n%lf Inch = %lf Meter",inch,meter);
break;
case 0:
goto exit;
default:
printf("\nYou enter invalid options.");
}
exit:
return 0;
}
The output of above program would be:
Figure: Screen shot for convert Meter to Inch C program |
Figure: Screen shot for convert Inch to Meter C program |
Comments
Post a Comment