C Program to Convert Kilometer to Miles

Here is a C program to convert distance from kilometers to miles. This program takes distance in kilometer(km) as input from user and convert it to Miles and prints it on screen. Here we are using Miles to Kilometer conversion factor of 1.6093, that means one mile is equal to 1.6093 kilometers.

C program to convert Kilometer to Miles

#include<stdio.h>

int main() {
    float MILEKM = 1.6093, FEETMETER = 3.2808;
    float km, meter = 0, feet, mile = 0;
    int m;

    printf("Enter the distance in kilometer\n");
    scanf("%f", &km);

    mile = km/MILEKM;
    printf("%.2fKm is equal to %.2f Mile OR \n", km, mile);
    mile = 0;
    
 if (km >= MILEKM) {
        while (1) {
            mile++;
            km = km - MILEKM;
            if (km < MILEKM)
                break;
        }
        
    }

    /* kilometer to meter conversion */
    meter = km * 1000;
    m = (int)meter;
    meter -= m;
    /* Meter to Feet conversion */
    feet = meter * FEETMETER;
    
    /* print the output */
    printf("%.2f miles, %d meter and %.2f feet\n",
        mile, m, feet);
    
    return 0;
}
Output
Enter the distance in kilometer
40
40.00Km is equal to 24.86 Mile OR 
24.00 miles, 1376 meter and 2.63 feet

Related Topics
C program to convert temperature from celsius to fahrenheit
C program to convert decimal numbers to binary numbers
C program to find all roots of quadratic equation
C program to make a simple calculator using switch statement
C program to multiply two numbers without using arithmetic operators
C program to convert number of days to week, months and years
C program to convert binary number to decimal number system
C Program to generate arithmetic progression(AP) series
C program to print fibonacci series using recursion
List of all C programs