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.

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

C Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.