C Program To Convert Kilometers to Meters

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

C Program To Convert Kilometers to Meters

One Kilometer is equal to 1000 meters, which is the conversion factor from kilometers into meters.

1 Km = 1,000 m

This program asks the user to enter distance in kilometres, then this program will convert it into metres using simple arithmetic logic.

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

C Program To Convert Kilometers to Meters

//C Program To Convert Kilometers into Meters
#include<stdio.h>
int main(){
  int m;
  float km;
  
  //Asking for input
  printf("Enter the distance in kilometers: ");
  scanf("%f", &km);
  
  //Kilometers into meters
  m = km * 1000;
  printf("%.2f in Kilometers = %d in Meters", km, m);
  return 0;
}

Output

Enter the distance in kilometers: 1.6
1.60 in Kilometers = 1600 in Meters

How Does This Program Work ?

  int m;
  float km;

In this program, we have declared one int data type variable and one float data type variable.

  //Asking for input
  printf("Enter the distance in kilometers: ");
  scanf("%f", &km);

Then, the user is asked to enter the value of kilometer.

  //Kilometers into meters
  m = km * 1000;

Now, we convert the kilometers into meters by multiplying the number by 1000.

 printf("%.2f in Kilometers = %d in Meters", km, m);

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

Conclusion

I hope after going through this post, you understand how to convert kilometers to meters 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 *