Link Search Menu Expand Document

Inches to centimeters

This is an example of how to convert Inches to cm (Inches to centimeters) using the C programming language, 1 inch = 2.54 cm.

file: inches_cm.c

#include <stdio.h>
#include <stdlib.h>

int main()

    float in_cm;
    char  in_inches[4];

    printf("Convert inches: ");
    scanf("%s", &in_inches);

    in_cm = atoi(in_inches)*2.54;

    printf("%.2f cmn", in_cm);


To compile the code with gcc:

$ gcc inches_cm.c -o inches_cm

Exmaple run:

$ ./inches_cm
Convert inches: 12
30.48 cm
$ ./inches_cm
Convert inches: 563478
1431234.12 cm