10.14.2012

Convert Inch to Feet and Feet to Inch

Q. Write a C program to convert Inch to Feet and Feet to Inch.

Ans.

keep in mind:

1 Foot  = 12 Inch
1 Inch  = 0.083 Foot

/*c program for convert inch to feet and vice-versa*/
#include<stdio.h>
int main()
{
 int ch;
 double foot,inch;
 printf("\nEnter 1 for convert Foot to Inch.");
 printf("\nEnter 2 for convert Inch to Foot.");
 printf("\nEnter 0 for exit.");
 printf("\n\nEnter your choice : ");
 scanf("%d", &ch);
 switch(ch)
 {
  case 1:
    printf("\nEnter value in Foot: ");
    scanf("%lf", &foot);
    inch = 12 * foot;
    printf("\n\t-- Convert Foot to Inch --\n");
    printf("\n%lf foot = %lf Inch",foot,inch);
    break;
  case 2:
    printf("\nEnter value in Inch: ");
    scanf("%lf", &inch);
    foot = (0.083) * inch;
    printf("\n\t-- Convert Inch to Foot --\n");
    printf("\n%lf Inch = %lf Foot",inch,foot);
    break;
  case 0:
    goto exit;
  default:
    printf("\nYou enter invalid options.");
 }
 exit:
 return 0;
}

The output of above program would be:


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


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

No comments:

Post a Comment