C Program to Convert Inches to Centimeters

In this post, we will learn how to convert inches to centimeters using the C Programming language.

1 inch is equal to 2.54 centimeters, which is the conversion factor from inches to cm.

We will be using the above conversion factor in our program to obtain the desired output.

So, without further ado, let’s begin this tutorial.

C Program to Convert Inches to Centimeters

// C Program to Convert Inches to Centimeters
#include <stdio.h>
int main(){
    float inches, cm;
    
    // Asking for input
    printf("Enter the length in inches: ");
    scanf("%f", &inches);
    
    // Inches to Centimeters
    cm = inches * 2.54;
    
    // Display output
    printf("%.2f Inches = %.2f Centimeters", inches, cm);
    return 0;
}

Output

Enter the length in inches: 21
21.00 Inches = 53.34 Centimeters

How Does This Program Work ?

    float inches, cm;

In this program, we have declared two float data type variables named inches and cm.

    // Asking for input
    printf("Enter the length in inches: ");
    scanf("%f", &inches);

Then, the user is asked to enter the length in inches.

    // Inches to Centimeters
    cm = inches * 2.54;

We convert inches to centimeters using the conversion factor 2.54.

    // Display output
    printf("%.2f Inches = %.2f Centimeters", inches, cm);

Finally, the result is printed on the screen using printf() function.

Conclusion

I hope after going through this post, you understand how to convert inches to centimeters using C Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *