Q:

Write a C program to convert feet to inches

0

C program to convert feet to inches

In this c program we are going to learn how to convert given feet into inches?

Let's understand what are feet and inches first...

Word Feet is a plural of foot which is a measurement unit of length and inch is also a measurement of unit length. A foot contains 12 inches.

So the logic to convert feet to inches is quite very simple, we have to just multiply 12 into the given feet (entered through the user) to get the measurement in inches.

In this example, we will read value of feet from the user and displays converted inches to the standard output device.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C program - Convert Feet to Inches

Let's consider the following example:

#include<stdio.h>

int main()
{
		int feet,inches;
		
		printf("Enter the value of feet: ");
		scanf("%d",&feet);
		
		//converting into inches
		inches=feet*12;
		
		printf("Total inches will be: %d\n",inches);
		return 0;
}

Output

    Enter the value of feet: 15 
    Total inches will be: 180

Using user define function

Here we are going to declare an user define function feet2Inches() this function will take feet as arguments and returns inches value.

#include<stdio.h>

//function feet2Inches
int feet2Inches(int f)
{
	return (f*12);
}

int main()
{
		int feet,inches;
		
		printf("Enter the value of feet: ");
		scanf("%d",&feet);
		
		//converting into inches
		inches=feet2Inches(feet);
		
		printf("Total inches will be: %d\n",inches);
		return 0;
}

Output

    Enter the value of feet: 15 
    Total inches will be: 180

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now