This blog is under construction

Sunday 7 July 2013

C program to convert minutes into hours

Write a C program to convert minutes into hours.


  #include <stdio.h>
  #define HOURTOMIN 60

  int main() {
        int minutes, hour = 0;

        /* get the input in minutes */
        printf("Enter the number of minutes:");
        scanf("%d", &minutes);

        printf("%d minutes = ", minutes);
        /* calculate no of hours in given no minutes */
        if (minutes > HOURTOMIN) {
                while (1) {
                        minutes = minutes - HOURTOMIN;
                        hour++;
                        if (minutes < HOURTOMIN)
                                break;
                }
        }

        /* print the no of hours and minutes */
        printf("%d hours and %d minutes\n", hour, minutes);
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter the number of minutes:69
  69 minutes = 1 hours and 9 minutes





See Also:

No comments:

Post a Comment