C Program to Convert Meter to Kilometer

In this article, we are going to understand and write a simple C program, in which, we are going to convert the distance from meter to kilometer. The C program for this is super simple, provided that you know the conversion formula, and you know how to write a C program.

C Program to Convert Meter to Kilometer

Here is the conversion formula for converting the distance from meter to kilometer –

km = m/1000

Here, m means the distance in meters, and km is the distance converted to kilometers. The conversion formula is very simple. You just need to take the distance in Meters, and then divide the value by 1000.

In the given video, you can find a detailed explanation and program for the conversion of the distance from meters to kilometers.

Here is the C program, to convert distance from meters to kilometers –

#include <stdio.h>

int main() {
double m, km;

// Prompt the user to enter a distance in meters
printf(“Enter distance in meters: “);
scanf(“%lf”, &m);

// Convert meters to kilometers
km = m / 1000;

// Display the converted distance in kilometers
printf(“%.2lf meters is equal to %.2lf kilometersn”, m, km);

return 0;
}

Program Output 1 –
Enter the distance in meters: 15000
15000.00 meters is equal to 15.00 kilometers

Program Output 2 –
Enter distance in meters: 120
120.00 meters is equal to 0.12 kilometers