The programs accept feet, yards, centimetres, and meters values as input and convert them into inches. And also from feet, yards, meters, cm to inches. They use various formulas for conversion and print the output on the screen. Below are the formulas that we will be using :
foot = 12 inches yard = 36 inches cm = 2.54 inches meter = 39.37 inches
In this article, we’ll be implementing programs for the following measurement into inches :
- Feet
- Yard
- Centimeter
- Meter
Program to Convert Feet to Inches and Inches to Feet
Feet to Inches
Feet, a measurement unit of length can be converted to its lower unit which is inch in this case. One foot is equal 12 inches. The program simply multiply 12 to convert the given foot/feet to inches.
Below are the examples.
Example 1. C program to convert feet to inches
Program
#include <stdio.h> int main (){ float feet, inches; printf ("\n Please enter a value of feet = "); scanf ("%f", &feet); inches = feet * 12; printf ("\n %.2f feet = %.2f inches \n\t \n", feet, inches); return 0; }
Output:
Please enter a value of feet = 3 3.00 feet = 36.00 inches
Example 2. C program to convert feet to inches using function
program:
#include <stdio.h> float getInchesFromFeet(float feet); int main (){ float feet, inches; printf ("\n Please enter a value of feet = "); scanf ("%f", &feet); inches = getInchesFromFeet(feet); printf ("\n %.2f feet = %.2f inches \n\t \n", feet, inches); return 0; } float getInchesFromFeet(float feet){ return feet * 12; }
Output:
Please enter a value of feet = 3 3.00 feet = 36.00 inches
Inches to Feet
We can also convert inches to feet by dividing the input value to 12. Below is the example.
Example 1. C program to convert inches to feet
#include <stdio.h> int main (){ float feet, inches; printf ("\n Please enter a value of inches = "); scanf ("%f", &inches); feet = inches / 12; printf ("\n %.2f inches = %.2f feet \n\t \n", inches, feet); return 0; }
Output:
Please enter a value of inches = 40 40.00 inches = 3.33 feet
Example 2. C program to convert inches to feet using function
Program:
#include <stdio.h> float getFeetFromInches(float x); int main (){ float feet, inches; printf ("\n Please enter a value of inches = "); scanf ("%f", &inches); feet = getFeetFromInches(inches); printf ("\n %.2f inches = %.2f feet \n\t \n", inches, feet); return 0; } float getFeetFromInches(float inches){ return inches/12; }
Output:
Please enter a value of inches = 30 30.00 inches = 2.50 feet
Program to Convert Yards to Inches and Inches to Yards
Yards to Inches
Yards is another measuring unit that is equivalent to 3 feet. Inches and feet are both lower measurement units. A yard is equal to 36 inches. We can simply multiply 36 to the given yards for converting them into inches.
Example 1. C program to convert yards to inches
Program:
#include <stdio.h> int main (){ float yards, inches; printf ("\n Please enter a value of yards = "); scanf ("%f", &yards); inches = yards * 36; printf ("\n %.2f yards = %.2f inches \n\t \n", yards,inches); return 0; }
Output:
Please enter a value of yards = 4 4.00 yards = 144.00 inches
Inches to Yards
In similar way, we can also convert inches to yards by dividing it to 36.
Example 1. C program to convert inches to yards
Program:
#include <stdio.h> int main (){ float yards, inches; printf ("\n Please enter a value of inches = "); scanf ("%f", &inches); yards = inches / 36; printf ("\n %.2f inches = %.2f yards \n\t \n", inches,yards); return 0; }
Output:
Please enter a value of inches = 45 45.00 inches = 1.25 yards
Program to Convert Centimeter to Inches and Inches to Centimeter
Inches to Centimeters
Another measurement unit for length is centimeter. When it comes to relation between centimeter and inches, one inches is equal to 2.54. We can simply multiply 2.54 with the input to calculate the measurement in inches.
Example 1. C program to convert inches to centimeters
Program:
#include <stdio.h> int main (){ float cm, inches; printf ("\n Please enter a value of inches = "); scanf ("%f", &inches); cm = inches * 2.54; printf ("\n %.2f inches = %.2f cm \n\t \n", inches,cm); return 0; }
Output:
Please enter a value of inches = 5 5.00 inches = 12.70 cm
Example 2. C program to convert inches to centimeters using function
Program:
#include <stdio.h> float getCmFromInches(float x); int main (){ float cm, inches; printf ("\n Please enter a value of inches = "); scanf ("%f", &inches); cm = getCmFromInches(inches); printf ("\n %.2f inches = %.2f cm \n\t \n", inches,cm); return 0; } float getCmFromInches(float inches){ return inches * 2.54; }
Output:
Please enter a value of inches = 5 5.00 inches = 12.70 cm
Centimeters to Inches
Likewise, we can also convert centimeters to inches by dividing the input to 2.54.
Example 1. C program to convert centimeters to inches
Program:
#include <stdio.h> int main (){ float cm, inches; printf ("\n Please enter a value of centimeters = "); scanf ("%f", &cm); inches = cm/2.54; printf ("\n %.2f cm = %.2f inches \n\t \n", cm,inches); return 0; }
Output:
Please enter a value of centimeters = 12.7 12.70 cm = 5.00 inches
Example 2. C program to convert centimeters to inches using functions
Program:
#include <stdio.h> float getInchesFromCm(float x); int main (){ float cm, inches; printf ("\n Please enter a value of centimeters = "); scanf ("%f", &cm); inches = getInchesFromCm(cm); printf ("\n %.2f cm = %.2f inches \n\t \n", cm,inches); return 0; } float getInchesFromCm(float cm){ return cm/2.54; }
Output:
Please enter a value of centimeters = 12.7 12.70 cm = 5.00 inches
Program to Convert Meters to Inches and Inches to Meters
Meters to inches
Inches and meters are both length measurement units. One meter is exactly equal to 39.37 inches. Similar to other, we need to divide 39.37 with the given meters to get output in inches.
Example 1. C program to convert meters to inches
Program:
#include <stdio.h> int main (){ float meters, inches; printf ("\n Please enter a value of meters = "); scanf ("%f", &meters); inches = meters * 39.37; printf ("\n %.2f meters = %.2f inches \n\t \n", meters,inches); return 0; }
Output:
Please enter a value of meters = 5 5.00 meters = 196.85 inches
Example 2. C program to convert meters to inches using functions
Program:
#include <stdio.h> float getInchesFromMeter(float x); int main (){ float meters, inches; printf ("\n Please enter a value of meters = "); scanf ("%f", &meters); inches = getInchesFromMeter(meters); printf ("\n %.2f meters = %.2f inches \n\t \n", meters,inches); return 0; } float getInchesFromMeter(float meters){ return meters * 39.37; }
Output:
Please enter a value of meters = 5 5.00 meters = 196.85 inches
Inches to Meters
To convert inches to meter, we need to divide the input provided as inches to 38.37 to convert it to meters.
Example 1. C program to convert inches to meters
Program:
#include <stdio.h> int main (){ float meters, inches; printf ("\n Please enter a value of inches = "); scanf ("%f", &inches); meters = inches / 39.37 ; printf ("\n %.2f inches = %.2f meters \n\t \n", inches,meters); return 0; }
Output:
Please enter a value of inches = 100 100.00 inches = 2.54 meters
Example 2. C program to convert inches to meters using function
Program:
#include <stdio.h> float getMeterFromInches(float x); int main (){ float meters, inches; printf ("\n Please enter a value of inches = "); scanf ("%f", &inches); meters = getMeterFromInches(inches); printf ("\n %.2f inches = %.2f meters \n\t \n", inches,meters); return 0; } float getMeterFromInches(float inches){ return inches / 39.37; }
Output:
Please enter a value of inches = 100 100.00 inches = 2.54 meters
Program to print measurement in inches
Program:
#include<stdio.h> int main() { float inches,meter,c_meter,yards,foot; printf("\n Please enter measurement in inches = "); scanf("%f",&inches); foot=inches*12; yards=inches*36; c_meter=inches*2.54; meter=inches*39.37; printf("\n %.2f inches = %.2f foot \n\t\t%.2f yards \n\t\t%.2f centimeter \n\t\t%.2f meter \n",inches,foot,yards,c_meter,meter); return 0; }
Output: