C Exercises: Calculate the total number of hours and minutes
6. Convert Minutes to Hours and Minutes
Write a program in C that takes minutes as input, and display the total number of hours and minutes.
Pictorial Presentation:

Sample Solution:
C Code:
#include <stdio.h> // Include the standard input/output header file.
int tot_mins; /* given number of minutes */
int hrs; /* number of hours (to be computed) */
int mins; /* number of minutes (to be computed) */
const int MINaHOUR = 60; /* number of minutes in an hour */
char line_text[50]; /* line of input from keyboard */
int main() {
printf("Input minutes: "); // Prompt the user to input minutes.
fgets(line_text, sizeof(line_text), stdin); // Read a line of input from the user and store it in 'line_text'.
sscanf(line_text, "%d", &tot_mins); // Convert the input to an integer and store it in 'tot_mins'.
hrs = (tot_mins / MINaHOUR); // Calculate the number of hours.
mins = (tot_mins % MINaHOUR); // Calculate the remaining minutes.
printf("%d Hours, %d Minutes.\n", hrs, mins); // Print the calculated hours and minutes.
return(0); // Return 0 to indicate successful execution of the program.
}
Sample Output:
Input minutes: 546 9 Hours, 6 Minutes.
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C program to convert a given number of minutes into days, hours, and minutes.
- Write a C program to convert minutes into hours and minutes using a long data type for handling very large minute values.
- Write a C program to perform the conversion of minutes to hours and minutes using a recursive function.
- Write a C program to convert minutes into hours and minutes, formatting the output with leading zeros where necessary.
C Programming Code Editor:
Previous: Write a C program that takes hours and minutes as input, and calculates the total number of minutes.
Next: Write a program in C that reads a firstname, lastname and year of birth and display the names and the year one after another sequentially.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics