This blog is under construction

Sunday, 7 July 2013

C program to convert centimeters to inches and feet

Write a C program to convert centimeters to inches and feet.


  #include <stdio.h>
  #define FEET2CM 30.48
  #define INCHTOCM 2.54
  int main() {
        float inches = 0.0, feet = 0.0, centimeter = 0.0;

        /* get the number of centimeter from the user */
        printf("Enter your input for centimeter:");
        scanf("%f", &centimeter);
        printf("%.f centimeter is equal to ", centimeter);

        /* calculating the number of feet */
        if (centimeter >= FEET2CM) {
                while (1) {
                        feet++;
                        centimeter = centimeter - FEET2CM;
                        if (centimeter < FEET2CM)
                                break;
                }
        }

        /* calculating the number of inches */
        inches = centimeter/INCHTOCM;

        /* print the result */
        printf("%.2f feet and %.2f inches\n", feet, inches);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter your input for centimeter:100
  100 centimeter is equal to 3.00 feet and 3.37 inches





See Also:

1 comment:

  1. Centimeters to Inches (cm to inches) conversion calculator for Length conversions with additional tables and formulas.

    ReplyDelete