This blog is under construction

Sunday 7 July 2013

C program to convert meter to feet and centimeters

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


  #include <stdio.h>
  #define METERTOCM 100
  #define FEETTOCM 30.48
  int main() {
        float meter, feet = 0, centimeter;

        /* get the input in meters from user */
        printf("Enter your input in meters:");
        scanf("%f", &meter);

        /* convert meter to centimeter */
        centimeter = meter * METERTOCM;

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

        /* print the number of feets and centimeters in given i/p */
        printf("%.2f meter = %.2f feet and %.2f centimeters\n",
                        meter, feet, centimeter);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter your input in meters:3050
  3050.00 meter = 10006.00 feet and 20.64 centimeters  





See Also:

No comments:

Post a Comment