In this guide, we will see programs to convert length given in feet to inches in various programming languages such as Java, C, C++, Python, PHP. Feet and inches both are the unit of lengths.
Formula to Convert Feet to Inches
inches = 12 * feet
Multiply the length given in feet by 12 to get the length in inches.
Input: 2 feet Output: 24 inches
Java Program
// Java program to convert length given in feet into inches class JavaExample { public static void main(String args []) { double feet = 2, inches; inches = 12 * feet; System.out.println(feet+ " feet = "+inches+" inches"); } }
Output:
2.0 feet = 24.0 inches
C Program
//Write C Program to convert feet to inches #include<stdio.h> int main() { float feet = 1.5f, inches; //declared feet and inches inches = 12 * feet; //feet to inches conversion printf ("%.2f feet = %.2f inches", feet, inches); return 0; }
Output:
1.50 feet = 18.00 inches
C++ Program
// C++ Program to Convert feet to inches #include <iostream> using namespace std; int main(){ double feet, inches; // User is asked to enter the length in feet cout << "Enter the length in feet: "; cin >> feet; // converting length from feet to inches inches = feet * 12; // displaying length in inches cout << "The length in inches is: " << inches; return 0; }
Output:
Python Program
# Python program to convert length given in feet to inches feet = float(input("Enter the length in feet: ")) # convert feet to inches by multiplying the value in feet by 12 inches = 12 * feet; print("The length in inches is: ",round(inches,3))
Output:
Enter the length in feet: 10 The length in inches is: 120.0
PHP Program
<?php // PHP program for feet to inches conversion $feet = .10; //length in feet $inches = 12 * $feet; //conversion from feet to inches echo("The length in inches is: " . $inches); ?>
Output:
The length in inches is: 1.2