C Program to Convert Feet into Inches

Posted in

C Program to Convert Feet into Inches
vinaykhatri

Vinay Khatri
Last updated on November 23, 2024

    In this article, we have written a program in C that can convert feet into inches. Both feet and inches are the measuring units of length. There are 12 inches in 1 foot, which is the singular form of feet. Hence, to convert feet into inches, we need to multiply the value of feet by 12. So here, we will write the logic in a C program that will accept a value of feet from the user, convert it into equivalent inches, and then print the same.

    C Program to Convert Feet into Inches

    Program Logic

    • Ask the user to enter a value for feet.
    • Multiply the value of feet by 12 and store it into a variable called inches.
    • Print the value of inches.

    Programming Approach

    There are two ways to write a program that can convert feet into inches. We can either write the complete code inside the main function or create a user-defined function. Both will work the same and contains the same logic. Here, we have written code for both programming approaches.

    1. C Program to Convert Feet into Inches (with the complete logic inside the main function)

    In this program, we will define the entire logic of converting feet into inches and printing the value inside the main function.

    #include<stdio.h>
    #include <conio.h>
    void main()
         {
           float f,i;
           clrscr();
           printf("Enter the Feet: ");
           scanf("%f",&f);
           i = f*12;
           printf("%f feet is equal to %0.2f inches \n", f,i);
           getch();
         }

    Output:

    Enter the Feet: 12.12
    12.12 feet is equal to 145.44 inches

    2. C Program to Convert Feet into Inches (using a user-defined function)

    Here, we will define a function that will contain the logic of converting feet into inches. Then, we will call this function from inside the main function and print the output.

    #include<stdio.h>
    #include <conio.h>
    
    float feet_to_inches(int f)
    {
    return (f*12);
    }
    void main()
    {
    float f,i;
    clrscr();
    printf("Enter the Feet: ");
    scanf("%f",&f);
    
    i = feet_to_inches(f);
    printf("%f feet is equal to %0.2f inches \n", f,i);
    getch();
    }

    Output:

    Enter the Feet: 12.12
    12.12 feet is equal to 145.44 inches

    Conclusion

    Converting feet into inches is a basic task. You simply need to multiply the value of feet by 12 to get its equivalent in inches, and that's what we have done above in two different ways.

    People are also reading:

    Leave a Comment on this Post

    0 Comments