Dremendo Tag Line

Calculate speed in C

scanf() - Question 20

In this question, we will see how to input distance in kilometer, time in minutes in C programming using the scanf() function and find the speed. To know more about scanf() function click on the scanf() function lesson.

Q20) Write a program in C to input distance in kilometer, time in minutes and find the speed.

Formula: Speed = Distance / Time

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int d,t;
    float s;
    printf("Enter distance in km ");
    scanf("%d",&d);
    printf("Enter time in minutes ");
    scanf("%d",&t);
    s=d/(float)t;
    printf("Speed = %.2f km per minute",s);
    return 0;
}

Output

Enter distance in km 70
Enter time in minutes 50
Speed = 1.40 km per minute
video-poster