Program to convert seconds to hour, minute and seconds

Problem statement:-  Program to convert seconds to an hour, minute, and seconds.

Data requirement:-

  Input Data:- t_sec

  Output Data:- hour, mint, sec 

Program in C

Here is the source code of the C Program to convert seconds to an hour, minute, and seconds.

Code:

#include<stdio.h>
int main()
{
    printf("Enter the total Second:");
    int t_sec;
    scanf("%d",&t_sec);
    int hour=t_sec/3600;
    t_sec=t_sec%3600;
    int mint=t_sec/60;
    int sec=t_sec%60;
    printf("Hours=%d\nMinutes=%d\nSecond=%d\n",hour,mint,sec);
}

Input/Output:
Enter the total Second:4089
Hours=1
Minutes=8
Second=9

Program in C++

Here is the source code of the C++ Program to convert seconds to an hour, minute, and seconds.

Code:

#include<iostream>
using namespace std;
int main()
{
    cout<<"Enter the total Second:";
    int t_sec;
    cin>>t_sec;
    int hour=t_sec/3600;
    t_sec=t_sec%3600;
    int mint=t_sec/60;
    int sec=t_sec%60;

    cout<<"Hours="<<hour<<"\nMinutes="<<mint<<"\nSecond="<<sec;
}

Input/Output:
Enter the total Second:51476
Hours=14
Minutes=17
Second=56

Program in Java
  
Here is the source code of the Java Program to convert seconds to an hour, minute, and seconds.

Code:

import java.util.Scanner;
public class SecondToHoursMinuteSecond {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the total Second:");
    int t_sec;
    t_sec=cs.nextInt();
    int hour=t_sec/3600;
    t_sec=t_sec%3600;
    int mint=t_sec/60;
    int sec=t_sec%60;
    System.out.println("Hours="+hour+"\nMinutes="+mint+"\nSecond="+sec);
     cs.close();
}
}

Input/Output:
Enter the total Second:
100005
Hours=27
Minutes=46
Second=45

Program in Python
  
Here is the source code of the Python Program to convert seconds to an hour, minute, and seconds.

Code:

t_sec=int(input("Enter the total Second:"))
hour=(int)(t_sec/3600)
t_sec=(int)(t_sec%3600)
mint=(int)(t_sec/60)
sec=(int)(t_sec%60)
print("Hours=",hour,"\nMinutes=",mint,"\nSecond=",sec)

Input/Output:

Post a Comment

0 Comments