C Exercises: Converts kilometers per hour to miles per hour
4. Kilometers per Hour to Miles per Hour Conversion
Write a C program that converts kilometers per hour to miles per hour.
Pictorial Presentation:

Sample Solution:
C Code:
#include <stdio.h>     // Include the standard input/output header file.
float kmph;              /* kilometers per hour */
float miph;              /* miles per hour (to be computed) */
char  line_text[50];      /* a line from the keyboard */
int main()
{
printf("Input kilometers per hour: ");   // Prompt the user to input kilometers per hour.
fgets(line_text, sizeof(line_text), stdin);   // Read a line of input from the user and store it in 'line_text'.
sscanf(line_text, "%f", &kmph);   // Convert the input to a float and store it in 'kmph'.
miph = (kmph * 0.6213712);   // Convert kilometers per hour to miles per hour.
printf("%f miles per hour\n", miph);   // Print the result in miles per hour.
return(0);   // Return 0 to indicate successful execution of the program.
}
Sample Output:
Input kilometers per hour: 15 9.320568 miles per hour
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to convert km/hr to miles/hr and vice versa, allowing the user to select the conversion direction.
 - Write a C program to convert an array of speeds from km/hr to miles/hr and display the maximum speed in miles/hr.
 - Write a C program to convert km/hr to miles/hr and round the result to the nearest tenth.
 - Write a C program to perform speed conversion from km/hr to miles/hr with robust error handling for non-numeric inputs.
 
Go to:
PREV : Rectangle Perimeter Calculation.
NEXT : Total Minutes Calculation.
C Programming Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
