Given an integer N, the task is to convert N minutes to seconds.
Note: 1 minute = 60 seconds
Examples:
Input: N = 5 Output: 300 seconds Explanation: 5 minutes is equivalent to 5 * 60 = 300 seconds
Input: N = 10 Explanation: 600 seconds Output: 10 minutes is equivalent to 10 * 60 = 600 seconds
Approach: To solve the problem, follow the below idea:
We know that 1 minute is equal to 60 seconds, so to convert N minutes to seconds, we can simply multiply N with 60 to get the total number of seconds.
Step-by-step approach:
- Take the input as the number of minutes N.
- Convert minutes to seconds by multiplying N with 60 and store it in ans.
- Print the final answer as ans.
Below is the implementation of the above approach:
C++
#include <iostream>
using namespace std;
int convertMinutesToSeconds( int N)
{
int ans = N * 60;
return ans;
}
int main()
{
int N = 10;
cout << convertMinutesToSeconds(N) << " seconds"
<< endl;
}
|
Java
import java.util.Scanner;
public class ConvertMinutesToSeconds {
static int convertMinutesToSeconds( int N) {
int ans = N * 60 ;
return ans;
}
public static void main(String[] args) {
int N = 10 ;
System.out.println(convertMinutesToSeconds(N) + " seconds" );
}
}
|
Python3
def convert_minutes_to_seconds(N):
ans = N * 60
return ans
if __name__ = = "__main__" :
N = 10
print (f "{convert_minutes_to_seconds(N)} seconds" )
|
C#
using System;
class Program
{
static int ConvertMinutesToSeconds( int N)
{
int ans = N * 60;
return ans;
}
static void Main()
{
int N = 10;
Console.WriteLine(ConvertMinutesToSeconds(N) + " seconds" );
}
}
|
Javascript
function convert_minutes_to_seconds(N) {
let ans = N * 60;
return ans;
}
if ( true ) {
const N = 10;
console.log(`${convert_minutes_to_seconds(N)} seconds`);
}
|
Time Complexity: O(1) Auxiliary Space: O(1)
|