Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Program to Convert Centimeter to Feet and Inches in C
Given with the length in centimeters as an input, the task is to convert the given length into feet and inches using C programming.
We can use length conversion formulas for this −
1 feet = 30.48 cm 1 inch = 2.54 cm
Syntax
double inches = centimeters * 0.3937; double feet = centimeters * 0.0328;
Algorithm
Start
Step 1 ? Declare function to perform conversion
double convert(int centimeter)
set double inch = 0.3937 * centimeter
set double feet = 0.0328 * centimeter
print inch and feet
Step 2 ? In main()
Declare and set int centimeter = 20
Call convert(centimeter)
Stop
Example
Here's a complete program to convert centimeters to feet and inches −
#include <stdio.h>
// Function to perform conversion
void convert(int centimeter) {
double inch = 0.3937 * centimeter;
double feet = 0.0328 * centimeter;
printf("Centimeters: %d<br>", centimeter);
printf("Inches: %.2f<br>", inch);
printf("Feet: %.2f<br>", feet);
}
// Driver Code
int main() {
int centimeter = 100;
convert(centimeter);
return 0;
}
Output
Centimeters: 100 Inches: 39.37 Feet: 3.28
Example 2: Converting to Feet and Remaining Inches
This approach shows conversion to feet with remaining inches displayed separately −
#include <stdio.h>
void convertToFeetInches(int centimeters) {
// Convert to total inches first
double totalInches = centimeters * 0.3937;
// Extract feet and remaining inches
int feet = (int)(totalInches / 12);
double remainingInches = totalInches - (feet * 12);
printf("Centimeters: %d<br>", centimeters);
printf("Conversion: %d feet and %.2f inches<br>", feet, remainingInches);
}
int main() {
int centimeters = 152;
convertToFeetInches(centimeters);
return 0;
}
Output
Centimeters: 152 Conversion: 4 feet and 11.84 inches
Conclusion
Converting centimeters to feet and inches in C involves simple multiplication with conversion factors. The first method gives separate decimal values, while the second shows practical feet-inches format commonly used in measurements.
Advertisements
