This blog is under construction

Sunday, 7 July 2013

C program to convert hours, minutes to seconds

Write a C program to convert hours, minutes to seconds.

  #include <stdio.h>
  int main() {
        int hour, min, seconds;

        /* get the input in hours */
        printf("Enter your input in hours:");
        scanf("%d", &hour);

        /* get the input from user in minutes */
        printf("Enter your input in minutes:");
        scanf("%d", &min);

        /* calculate the number of seconds */
        seconds = (min * 60) + (hour * 3600);

        /* print the results */
        printf("%d hour and %d minutes = ", hour, min);
        printf("%d seconds\n", seconds);
        return 0;

  jp@jp-VirtualBox:~/cpgms/lab_pgms/01_cbasics$ ./a.out
  Enter your input in hours:1
  Enter your input in minutes:60
  1 hour and 60 minutes = 7200 seconds

See Also:

No comments:

Post a Comment