• Language

    C

  • Description

    Need to write a program to convert Seconds in to Hours Minutes and Seconds. You should obtain number of seconds as user input (Integer Value). Convert the seconds obtain in to Hours, Minutes and Seconds and display that to the User.
    Need to have the output of the code in this format:
    Enter a number of seconds: 500
    Here is the time in hours, minutes, and seconds:
    Hours: 0.0
    Minutes: 8.0
    Seconds: 20.0
    where "500" is the input and the other numbers are the output.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
#include <stdlib.h>

int main (void)
{
    int hours, minutes, number_of_seconds, seconds;
    printf ("Enter the value of number of seconds: ");
    scanf ("%d", &number_of_seconds);
    (void) getchar ();
    seconds=number_of_seconds%60;
    minutes=(number_of_seconds-seconds)/60;
    hours=(minutes-minutes%60)/60;
    minutes=minutes%60;
    printf ("Value of hours: %d\n", hours);
    printf ("Value of minutes: %d\n", minutes);
    printf ("Value of seconds: %d\n", seconds);
    putchar ('\n');
    system ("pause");
    return EXIT_SUCCESS;
}