Friday, April 11, 2014

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("
Enter 1 for convert Meter to Inch."
);

 printf("
Enter 2 for convert Inch to Meter."
);

 printf("
Enter 0 for exit."
);

 printf("

Enter your choice : "
);

 scanf("%d", &ch);
 switch(ch)
 {
  case 1:
    printf("
Enter value in Meter: "
);

    scanf("%lf", &meter);
    inch = (39.37) * meter;
    printf("
-- Convert Meter to Inch --
"
);

    printf("
%lf meter = %lf Inch"
,meter,inch);

    break;
  case 2:
    printf("
Enter value in Inch: "
);

    scanf("%lf", &inch);
    meter = (.025) * inch;
    printf("
-- Convert Inch to meter --
"
);

    printf("
%lf Inch = %lf Meter"
,inch,meter);

    break;
  case 0:
    goto exit;
  default:
    printf("
You enter invalid options."
);

 }
 exit:
 return 0;
}


The output of above program would be:


Output of convert Meter to Inch C program
Figure: Screen shot for
convert Meter to Inch C program


Output of convert Inch to Meter C program
Figure: Screen shot for 
convert Inch to Meter C program

Related Posts by Categories

Categories: , , , ,

0 comments:

Post a Comment