In this article, we are going to have a look at a simple C program, with which, we are going to convert the given length from Kilometer to meters. The conversion is very simple, you just need to know the conversion formula, and the basic C programming syntax, and you should simply be able to write a C program for the conversion of distance from kilometer to meter.
C Program to convert Kilometer to Meter
Here is the simple conversion formula for converting distance from kilometer to meter –
m = km*1000
Here, km is the distance in kilometers, and m is the distance converted to meters.
In the given video, you can find the detailed explanation and program for converting distance from kilometer to meter.
Here is the C program to convert distance from kilometers to meters.
#include <stdio.h>
int main() {
double km, m;
// Asking the user for distance in kilometers
printf(“Enter distance in kilometers: “);
scanf(“%lf”, &km);
// Converting kilometers to meters
m = km * 1000;
// Display the output
printf(“%.2lf kilometers is %.2lf metersn”, km, m);
return 0;
}
Program Output Example 1-
Enter distance in kilometers: 5
5.00 kilometers is 5000.00 meters
Program Output Example 2 –
Enter distance in kilometers: 6.5
6.50 kilometers is 6500.00 meters