-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuestion 2.c
22 lines (19 loc) · 860 Bytes
/
Question 2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* The distance between two cities (in km) is input through the keyboard, write a program to convert
and print this distance in meters, feet, inches and centimetres. */
#include <stdio.h>
int main() {
double distanceInKm;
// Input the distance in kilometers
printf("Enter the distance between two cities (in kilometers): ");
scanf("%lf", &distanceInKm);
// Conversion factors
double meters = distanceInKm * 1000;
double feet = distanceInKm * 3280.84;
double inches = distanceInKm * 39370.1;
double centimeters = distanceInKm * 100000;
// Display the converted distances
printf("Distance in meters: %.2lf\n", meters);
printf("Distance in feet: %.2lf\n", feet);
printf("Distance in inches: %.2lf\n", inches);
printf("Distance in centimeters: %.2lf\n", centimeters);
return 0;}