Program to convert time from seconds to hours, minutes and seconds
C Programming
#include<stdio.h>
int main( ) {
int seconds;
int hours,minutes,remainingSeconds;
printf("Enter the time in seconds: ");
scanf("%d",&seconds);
hours = seconds / 3600;
remainingSeconds = seconds % 3600;
minutes = remainingSeconds / 60;
remainingSeconds = remainingSeconds % 60;
printf("%d seconds is %d hours %d minutes %d seconds",seconds,hours,minutes,remainingSeconds);
return 0;
}
C++ Programming
#include<iostream>
using namespace std;
int main( ) {
int seconds;
cout << "Enter the time in seconds: ";
cin >> seconds;
int remainingSeconds;
int hours = seconds / 3600;
remainingSeconds = seconds % 3600;
int minutes = remainingSeconds / 60;
remainingSeconds = remainingSeconds % 60;
cout << seconds << " is "<< hours << " hours "<< minutes << " minutes "<< remainingSeconds << endl;
return 0;
}
Java
import java.util.Scanner;
class DisplayTime {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the time in seconds: ");
int seconds = sc.nextInt();
int remaingSeconds;
int hours = seconds / 3600;
remaingSeconds = seconds % 3600;
int minutes = remaingSeconds / 60;
remaingSeconds = remaingSeconds % 60;
System.out.println(seconds+" seconds is "+hours+" hours "+minutes+" minutes and "+remaingSeconds+" seconds");
}
}
Go Lang
package main
import "fmt"
func main() {
var seconds int32
fmt.Print("Enter the time in seconds: ")
fmt.Scan(&seconds)
hours := seconds / 3600
remainingSecons := seconds % 3600
minutes := remainingSecons / 60
remainingSecons = remainingSecons % 60
fmt.Printf("%d seconds is %d hours %d minutes and %d seconds",seconds,hours,minutes,remainingSecons)
}
PHP
<?php
if(isset($_POST['sub'])) {
$seconds = $_POST['seconds'];
$hours = (int)($seconds / 3600);
$remainingSeconds = $seconds % 3600;
$minutes = (int)($remainingSeconds / 60);
$remainingSeconds = $remainingSeconds % 60;
echo $seconds." is ".$hours." hours ".$minutes." minutes ".$remainingSeconds." seconds";
}
?>
if(isset($_POST['sub'])) {
$seconds = $_POST['seconds'];
$hours = (int)($seconds / 3600);
$remainingSeconds = $seconds % 3600;
$minutes = (int)($remainingSeconds / 60);
$remainingSeconds = $remainingSeconds % 60;
echo $seconds." is ".$hours." hours ".$minutes." minutes ".$remainingSeconds." seconds";
}
?>
Comments