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
C Keywords
C Variables
C Data Types
C Constants
C printf and scanf
C Escape Sequences
C Format Specifiers
Exercises & Assignments
Write a C program to swap the values of two variables using a third variable
Write a C program to print words using spacing and new line characters
Write a C program to get the salary from the user and print it
Write a C program to find the size of int, float, long, double and char
Write a C program to get the marks of 5 subjects and find the total and average
Write a C program to calculate the perimeter of a rectangle
Write a C program to convert minutes into hours and minutes
Interview Questions & Answers
What is the difference between a variable and a constant in C?
What are the data types in C?
What is the difference between = and == in C?
What is the difference between ++i and i++ in C?
What is the use of the sizeof operator in C?
How to swap two numbers in C?