Write a C Program to Convert Seconds into Hours, Minutes and Seconds

January 12, 2023 0 Comments

In this tutorial learn how you can convert seconds into hours, minutes and seconds. There are 3600 seconds in 1 hour and 60 seconds in 1 minute.

For a hours we first divide seconds by 3600 and for a minutes first, we take the remainder of the hours then divide the remainder by 60.  And for seconds we take the remainder of hours then divide the remainder by 60 and again take the remainder as remaining seconds. By this, we get hours and minutes, and seconds.

C programming is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, etc.

Write a Program to Convert Seconds into Hours, Minutes and Seconds

Here is the code to convert seconds into hours, minutes, and seconds in C programming.

#include <stdio.h> //WAP to convert seconds into hours, minutes and seconds.
int main(){
    int seconds,hours,minutes,second;
    printf("Please enter no of seonds:");
    scanf("%d",&seconds);
    hours=seconds/3600;
    minutes= (seconds%3600)/60;
    second=(seconds%3600)%60;
    printf("%d seconds is equals to %d hours %d minutes %d seconds.",seconds,hours,minutes,second);

    return 0;
}

Test Live At Jdoodle

Conclusion

This is how you can convert seconds into hours, minutes and seconds in c programming. Comment below if you like our tutorial.

Leave a comment

Gallery