Calculate Hours ,Minutes And Seconds From Given Seconds in C Programming



#include <stdio.h>

int main()
{
    int sec, hr, min;
    printf("\nEnter Seconds :");
    scanf("%d", &sec);
    min = sec/60;
    sec = sec%60;
   
    if(min>=60)
    {
        hr = min/60;
        min = min%60;
    }
   if (hr !=0 )
    {
        printf("\nNo of Hours : %d", hr);
        printf("\nNo of Minutes : %d", min);
        printf("\nNo of Seconds : %d", sec);
    }
    else 
    {
        printf("\nNo of Minutes : %d", min);
        printf("\nNo of Seconds : %d", sec);
    }
   }

Comments