Convert Feet to Meter and Meter to Feet

Q. Write a C program to convert meter to foot and feet to meter.

Ans.

keep in mind:

1 Meter = 3.28 Foot
1 Foot  = 0.30 Meter

/*c program for convert meter to foot and vice-versa*/
#include<stdio.h>
int main()
{
 int ch;
 double meter,foot;
 printf("\nEnter 1 for convert meter to foot.");
 printf("\nEnter 2 for convert foot 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);
    foot = (3.28084) * meter;
    printf("\n\t-- Convert Meter to Foot --\n");
    printf("\n%lf meter = %lf foot",meter,foot);
    break;
  case 2:
    printf("\nEnter value in foot: ");
    scanf("%lf", &foot);
    meter = (.3048) * foot;
    printf("\n\t-- Convert Foot to meter --\n");
    printf("\n%lf foot = %lf meter",foot,meter);
    break;
  case 0:
    goto exit;
  default:
    printf("\nYou enter invalid options.");
 }
 exit:
 return 0;
}


The output of above program would be:


Output of convert meter to feet C program
Figure: Screen shot for convert meter to feet C program



Output of convert feet to meter C program
Figure: Screen shot for convert feet to meter C program

Comments