write a program that prompts the user to enter a length in feet and inches and outputs the equivalent length in centimetres.
Answers
import java.util.Scanner;
import java.lang.Math;
class Test
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter Length in Feet:");
int feet= input.nextInt();
System.out.println("Enter Length in Inches:");
int inches= input.nextInt();
double centi=0;
centi=(feet*30)+(inches*2.54);
int c=(int)Math.round(centi);
System.out.println("Centimetres :"+c);
}
}
Output :
Enter Length in Feet:5
Enter Length in Inches:6
Centimetres :165
If you find my answer helpful then mark me as brainliest! Thank you.
C program that prompts the user to enter a length in feet and inches and outputs the equivalent length in centimetres is shown below.
- First we convert feet to inches using the formula that 1 feet = 12 inches and then we find total inches.
- Next we convert the total length in inches to cm as 1 inch = 2.54cm.
#include<stdio.h>
int main()
{
int feet,inches,cm;
printf("Enter the value of feet: ");
scanf("%d",&feet);
printf("Enter the value of inches: ");
scanf("%d",&inches);
//converting into inches
inches= inches + (feet*12);
.//converting to cm.
cm = 2.54*inches
printf("Total value in cm will be: %d\n",cm);
return 0;
}