Program to Convert Minutes to Hours
- Write a program to Convert Minutes to Hours in C
- Write a program to Convert Minutes to Hours in C++
- Write a program to Convert Minutes to Hours in Python
- Write a program to Convert Minutes to Hours in PHP
- Write a program to Convert Minutes to Hours in Java
- Write a program to Convert Minutes to Hours in Java Script
- Write a program to Convert Minutes to Hours in C#
Explanation:
To convert minutes to hours, use the following formula:
Hours= Minutes / 60
Here:
- Divide the total number of minutes by 60, since there are 60 minutes in an hour.
- The result will be in decimal form. If needed, you can also separate it into hours and remaining minutes
Example
If the total minutes are 125:
- Total hours: 125 ÷ 60 = 2.0833
- Split into whole hours and remaining minutes:
- Hours: 2
- Remaining minutes: 125 mod 60 = 5
- Result: 2 hours and 5 minutes
Program to Convert Minutes to Hours
-
C
-
C++
-
Python
-
PHP
-
JAVA
-
Java Script
-
C#
#include <stdio.h> int main() { int minutes; float hours; // Input minutes printf("Enter time in minutes: "); scanf("%d", &minutes); // Convert to hours hours = minutes / 60.0; // Output the result printf("%d minutes is equal to %.2f hours.\n", minutes, hours); return 0; }
#include <iostream> using namespace std; int main() { int minutes; float hours; // Input minutes cout << "Enter time in minutes: "; cin >> minutes; // Convert to hours hours = minutes / 60.0; // Output the result cout << minutes << " minutes is equal to " << hours << " hours." << endl; return 0; }
minutes = int(input("Enter time in minutes: ")) # Convert to hours hours = minutes / 60.0 # Output the result print(f"{minutes} minutes is equal to {hours:.2f} hours.")
<?php // Input minutes $minutes = (int)readline("Enter time in minutes: "); // Convert to hours $hours = $minutes / 60.0; // Output the result echo "$minutes minutes is equal to " . number_format($hours, 2) . " hours.\n"; ?>
import java.util.Scanner; public class MinutesToHours { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Input minutes System.out.print("Enter time in minutes: "); int minutes = scanner.nextInt(); // Convert to hours double hours = minutes / 60.0; // Output the result System.out.printf("%d minutes is equal to %.2f hours.\n", minutes, hours); scanner.close(); } }
let minutes = parseInt(prompt("Enter time in minutes: ")); // Convert to hours let hours = minutes / 60.0; // Output the result console.log(`${minutes} minutes is equal to ${hours.toFixed(2)} hours.`);
using System; class Program { static void Main() { // Input minutes Console.Write("Enter time in minutes: "); int minutes = Convert.ToInt32(Console.ReadLine()); // Convert to hours double hours = minutes / 60.0; // Output the result Console.WriteLine($"{minutes} minutes is equal to {hours:F2} hours."); } }