Write a C program to convert minutes into hours and minutes

Description: Take the total minutes from the user, and print how many hours and minutes it is.

Hint:

  • Hours = minutes / 60 (integer division). Remaining minutes = minutes % 60.

C program to convert minutes to hours and minutes

#include <stdio.h>

int main(void) {
    int total, hours, minutes;

    printf("Enter minutes: ");
    scanf("%d", &total);

    hours = total / 60;
    minutes = total % 60;
    printf("%d minutes = %d hours and %d minutes\n", total, hours, minutes);
    return 0;
}

Output:

Output of the above program is

Enter minutes: 135
135 minutes = 2 hours and 15 minutes

How it works

  • 135 / 60 is 2 (integer division), so there are 2 full hours.
  • 135 % 60 is 15, the minutes which are left.

Read C Operators.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.