C Program to Convert Inches to Centimeters

In this article, we'll look at how to write a C program that asks the user for a length (in inches) and then converts and prints the equivalent length in centimeters. But before going through the program given below, let's first understand the relationship between an inch and a centimeter.

Relationship between an inch and a centimeter

The relationship between an inch and a centimeter is written as:

1 centimeter = 0.3937 inches

or,

1 inch = 2.54 centimeters

Note: The spelling "centimetre" is used as international spelling, whereas "centimeter" is used as American spelling.

Note: A centimeter is equal to one hundredth of a meter.

A centimeter is represented by (cm), whereas an inch is represented by (" or in"). Therefore, we can write:

1" = 2.54 cm

Now let's move on to the program.

Converting inches to centimeters in C

The question is, "Write a program in C that converts length from inch to centimeter." The answer to this question is given below:

#include<stdio.h>
#include<conio.h>
int main()
{
    float inch, cm;
    printf("Enter length in Inch: ");
    scanf("%f", &inch);
    cm = inch * 2.54;
    printf("Equivalent length in Centimeters = %0.2f", cm);
    getch();
    return 0;
}

As the above program was written in the Code::Blocks IDE, here is the snapshot of the sample run:

c program convert inches to centimeters

Now supply any length in inches, say 12, and press the ENTER key to see the same length in centimeters. Here is the second snapshot of the sample run:

convert inches to centimeters c program

Here are some of the main steps used in the above program:

C Quiz


« Previous Program Next Program »


Liked this post? Share it!