Converts time in minutes to time in hours and minutes. - C Data Type

C examples for Data Type:int

Introduction

Use #define or const to create a symbolic constant for 60.

Use a while loop to allow the user to enter values repeatedly and terminate the loop if a value for the time of 0 or less is entered.

Demo Code

#include <stdio.h>  

int main(void) {  

    const int minperhour = 60;  
    int minutes, hours, mins;  
      //  ww w .ja  v  a2  s. c o  m
    printf("Enter the number of minutes to convert: ");  
    scanf("%d", &minutes);  

    while (minutes > 0 ) {  
        hours = minutes / minperhour;  
        mins = minutes % minperhour;  
        printf("%d minutes = %d hours, %d minutes\n", minutes, hours, mins);  
        printf("Enter next minutes value (0 to quit): ");  
        scanf("%d", &minutes);  
    }  
    printf("Bye\n");  
      
    return 0;  
}

Result


Related Tutorials