In this tutorial, we will see how to convert a given value in centimeters to feet and inches.
Here, we are given a value in centimeters and our task is to convert that value to inches and feet. As we know, 1 inch is equal to 2.54 centimeter, so 1 centimeter is equal to 0.3937 inches( as 1/2.54 = 0.3937). So, n centimeter is equal to n*0.3937 inches.
Similarly, 1 foot is equal to 30.48 centimeter, therefore, 1 centimeter is equal to 0.0328 feet( 1/30.48 = 0.0328). So, n centimeter is equal to n*0.0328 foot.
Let us look at the below examples for a better understanding of the above logic.
Java program to convert centimeter to Feet and Inches
In this program, we will see how to convert a given value in centimeters to feet and inches in java.
Algorithm:
-
Start
-
Create an instance of the Scanner class.
-
Declare a variable to store the value in centimeters.
-
Ask the user to initialize this variable.
-
Call a user-defined method to convert the value to inches and feet.
-
In order to convert the value into inches, multiply the given value in centimeter with 0.3937
-
In order to convert the value into feet, multiply the given value in centimeter with 0.0328
-
Display the result in inches.
-
Display the result in feet.
-
Stop.
Let us look at the below example for a better understanding of the above algorithm.
// Java program to convert a value in centimeter to Feet and Inches
import java.io.*;
import java.util.Scanner;
public class Main
{
// User-definned Method to convert centimeter to inches
static double convertToInches(int cm)
{
double inch = 0.3937 * cm;
double feet = 0.0328 * cm;
System.out.printf("Value in inches is: %.2f \n", inch);
System.out.printf("Value in feet is: %.2f", feet);
return 0;
}
// Driver Code
public static void main(String args[])
{
//Create instance of the Scanner class
//Take input from the user
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Value in centimeter: ");
int cm = sc.nextInt();
//Calling a user-defined method
convertToInches(cm);
}
}
Enter the Value in centimeter: 123
Value in inches is: 48.43
Value in feet is: 4.03
C program to convert centimeter to Feet and Inches
In this program, we will see how to convert a given value in centimeters to feet and inches in C.
Algorithm:
-
Start
-
Declare a variable to store the value in centimeters.
-
Ask the user to initialize this variable.
-
Call a user-defined function to convert the value to inches and feet.
-
In order to convert the value into inches, multiply the given value in centimeter with 0.3937
-
In order to convert the value into feet, multiply the given value in centimeter with 0.0328
-
Display the result in inches.
-
Display the result in feet.
-
Stop.
Let us look at the below example for a better understanding of the above algorithm.
// C program to convert a value in centimeter to Feet and Inches
#include <stdio.h>
// Function to convert centimeter to inches
double convertToInches(int cm)
{
double inch = 0.3937 * cm;
double feet = 0.0328 * cm;
printf ("Value in inches is: %.2f \n", inch);
printf ("Value in feet is: %.2f", feet);
return 0;
}
// Driver Code
int main()
{
printf ("Enter the value in centimeter: \n");
int cm;
scanf("%d",&cm);
convertToInches(cm);
return 0;
}
Enter the value in centimeter: 432
Value in inches is: 170.08
Value in feet is: 14.17
C++ Program to convert centimeter to Feet and Inches
In this program, we will see how to convert a given value in centimeters to feet and inches in C++.
Algorithm:
-
Start
-
Declare a variable to store the value in centimeters.
-
Ask the user to initialize this variable.
-
In order to convert the value into inches, multiply the given value in centimeter with 0.3937
-
In order to convert the value into feet, multiply the given value in centimeter with 0.0328
-
Display the result in inches.
-
Display the result in feet.
-
Stop.
Let us look at the below example for a better understanding of the above algorithm.
//C++ Program to convert a value in centimeter to inches and feet
#include<iostream>
using namespace std;
int main()
{
float cm;
cout<<"Enter the value in centimeters: "<<endl;
cin>>cm;
double inch = 0.3937 * cm;
double feet = 0.0328 * cm;
cout<<"Value in inches is equals to "<<inch<<endl;
cout<<"Value in feet is equals to "<<feet<<endl;
return 0;
}
Enter the value in centimeter: 239
Value in inches is equals to 94.0943
Value in feet is equals to 7.8392
Conclusion:
In this tutorial, we saw how to convert a value in centimeters to inches and feet by using three different programming languages.
You may also like: