Skip to content

Convert Minutes To Seconds

Updated: at 09:19 PM

Table of contents

Open Table of contents

Write a program to convert minutes to seconds

1 minute = 60 seconds

Input  : 5
Output : 300

C

// Write a C program to convert minutes to seconds

#include <stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    printf("%d\n",n*60);
    return 0;
}

//Contributed by Raghav Garg

C#

// Write a C# program to convert minutes to seconds

// C# program to convert minutes in seconds

using System;

class GFG
{


static void convertMinutes(int n)
{
int  seconds;


	seconds = n * 60;

	Console.WriteLine(seconds);
}

// Driver code
public static void Main ()
{
	int n = Console.ReadLine();
	convertMinutes(n);
}
}

C++

// Write a C++ program to convert minutes to seconds

/**
 * NAME: JASMIN, RAMON EMMIEL P.
 * DATE: February 24, 2023
 * COUNTRY: Philippines
 */

#include <iostream>
using namespace std;

int convertMinutesToSeconds(int);

int main(){

    int sampleMinute = 5;

    cout << convertMinutesToSeconds(sampleMinute) << endl;

    return 0;
}

int convertMinutesToSeconds(int minutes){
    return minutes*60;
}

Dart

// Write a Dart program to convert minutes to seconds

void main() {
  print(convertMinutesToSeconds());
}

int convertMinutesToSeconds({int days = 5}) {
  int secondsInMinute = 60;
  return secondsInMinute * days;
}

F#

// Write a F# program to convert minutes to seconds

let minutesToSeconds mins : int =
  mins * 60

let seconds =  minutesToSeconds 5

printfn "Equivalent seconds : %d" seconds

Go

// Write a Go program to convert minutes to seconds

package main

import "fmt"

func minutesToSeconds(nums int) int {
	return nums * 60
}

func main() {
	var i int

	fmt.Print("Input Minutes: ")
	fmt.Scan(&i)
	fmt.Println(minutesToSeconds(i))
}

Haskell

-- Write a Haskell program to convert minutes to seconds

main :: IO ()
main = do
   putStrLn "Enter minutes: "
   input1 <- getLine
   let minutes = read input1 :: Float

   let seconds = minutes * 60
   putStrLn $ show (seconds)

Java

// Write a Java program to convert minutes to seconds

import java.util.Scanner;
class minutesToSeconds
{
	int sec;
	void seconds(int m)
	{
	  sec=m*60;
	}
	public static void main(String[] arg)
	{
	int min;
	Scanner sc=new Scanner(System.in);
	System.out.println("Enter Minutes");
	min=sc.nextInt();
	minutesToSeconds res=new minutesToSeconds();
	res.seconds(min);
	System.out.println("Seconds: "+res.sec);
	}
}

JavaScript

// Write a JavaScript program to convert minutes to seconds

/**
 *
 * @name This program converts minutes into seconds
 * @param {number} minutes
 * @returns {number} seconds
 *
 * @example
 * ```js
 * const area1 = ConvertMinutesToSeconds(5) // 300
 * const area2 = ConvertMinutesToSeconds(1) // 60
 * ```
 */
function ConvertMinutesToSeconds(minutes) {
  return minutes * 60;
}

// Console Tests
console.log("Number of seconds in 5 minutes.");
console.log("That is" + ConvertMinutesToSeconds(5) + "// 300");

console.log("Number of seconds in 15 minutes.");
console.log("That is" + ConvertMinutesToSeconds(15) + "// 900");

console.log("Number of seconds in 2.5 minutes.");
console.log("That is" + ConvertMinutesToSeconds(2.5) + "// 150");

Julia

# Write a Julia program to convert minutes to seconds

println("Enter value in minutes: ")
min = parse(Int, readline())
sec = min * 60
println(min, " minutes equals ", sec, " seconds")

Kotlin

// Write a Kotlin program to convert minutes to seconds

import java.util.concurrent.TimeUnit

fun main(args: Array<String>) {

    val minutes: Long = 180
    val seconds = TimeUnit.MINUTES.toSeconds(minutes)
    println("$minutes Minutes = $seconds seconds")
}

Perl

# Write a Perl program to convert minutes to seconds

#!/usr/bin/perl
use warnings;
use strict;
print "Enter the minutes : ";
my $mins = <STDIN>;
my $seconds = $mins * 60;
print $mins." minutes are ".$seconds." seconds\n";

PHP

// Write a PHP program to convert minutes to seconds

<?php
  $x = readline('Enter Minutes: ');

  $x1 = $x * 60;
  echo "Seconds: $x1 \n";
?>

Python

# Write a Python program to convert minutes to seconds

# asking for input
totalminutes = input(f"Enter the minutes: ")

# checking for only digit in input
if totalminutes.isdigit():
    # converting string type to int type
    totalminutes = int(totalminutes)

    # calculating on basis of formula
    totalSeconds = totalminutes * 60

    # printing the output
    print(f"Total time: {totalSeconds} seconds")

# user type input other than digit
else:
    print(f"Please enter valid input.")

R

# Write a R program to convert minutes to seconds

minutes = 5
seconds = minutes * 60
cat("seconds: ", seconds)

Ruby

# Write a Ruby program to convert minutes to seconds

def convert_to_seconds(minutes)
    seconds_in_minute = 60
    return minutes * seconds_in_minute
end

Rust

// Write a Rust program to convert minutes to seconds

use std::io;

fn main() {
    println!("Enter the number of minutes:");
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read input.");

    let minutes: u32 = match input.trim().parse() {
        Ok(num) => num,
        Err(_) => {
            println!("Invalid input. Please enter a valid number of minutes.");
            return;
        }
    };

    let seconds = minutes * 60;

    println!("{} minutes is equal to {} seconds.", minutes, seconds);
}

Scala

// Write a Scala program to convert minutes to seconds

object HelloWorld {
	def main(args: Array[String]): Unit = {
	  val minutes = scala.io.StdIn.readInt();
	  println("Seconds: " + minutes * 60);
	}
}

Swift

// Write a Swift program to convert minutes to seconds

import Swift
import Foundation

var minutes = 5

var seconds = minutes * 60
print("Seconds: ", seconds)

TypeScript

// Write a TypeScript program to convert minutes to seconds

/**
 *
 * @name This program converts minutes into seconds
 * @param {number} minutes
 * @returns {number} seconds
 *
 * @example
 * ```ts
 * const area1 = ConvertMinutesToSecondsTS(5) // 300
 * const area2 = ConvertMinutesToSecondsTS(1) // 60
 * ```
 */
function ConvertMinutesToSecondsTS(minutes: number) {
  return minutes * 60;
}

// Console Tests
console.log("Number of seconds in 5 minutes.");
console.log("That is" + ConvertMinutesToSecondsTS(5) + "// 300");

console.log("Number of seconds in 15 minutes.");
console.log("That is" + ConvertMinutesToSecondsTS(15) + "// 900");

console.log("Number of seconds in 2.5 minutes.");
console.log("That is" + ConvertMinutesToSecondsTS(2.5) + "// 150");

Similar programs