﻿ C exercises: Converts kilometers per hour to miles per hour - w3resource

# C Exercises: Converts kilometers per hour to miles per hour

## C Input Output statement: Exercise-4 with Solution

Write a C program that converts kilometers per hour to miles per hour.

Sample Solution:

C Code:

``````#include <stdio.h>
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: ");
fgets(line_text, sizeof(line_text), stdin);
sscanf(line_text, "%f", &kmph);

miph = (kmph * 0.6213712);
printf("%f miles per hour\n", miph);

return(0);
}
```
```

Sample Output:

```Input kilometers per hour: 15
9.320568 miles per hour
```

C Programming Code Editor:

```#include <stdio.h>

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: ");
fgets(line_text, sizeof(line_text), stdin);
sscanf(line_text, "%f", &kmph);

miph = (kmph * 0.6213712);
printf("%f miles per hour\n", miph);

return(0);
}```

Improve this sample solution and post your code through Disqus.