Ad
Fundamentals
Strings
Data Types

You will be given a number of minutes. Your task is to return a string on the heap that formats the number into 'hours:minutes".

Make sure you always return two integers for the minutes section of the conversion.

i.e. ('0:01' instead of '0:1')

Example:

minutes(90) => '1:30'

Code
Diff
  • char *minutes(int num){
      char *ret = calloc(64, sizeof(char));
      sprintf(ret, "%d:%02d", (num / 60), (num % 60));
      return ret;
    }
    • function minutes(num){
    • return num % 60 < 10 ? Math.floor(num/60) + ':' + '0' + (num % 60) : Math.floor(num/60) + ':' + (num % 60)
    • char *minutes(int num){
    • char *ret = calloc(64, sizeof(char));
    • sprintf(ret, "%d:%02d", (num / 60), (num % 60));
    • return ret;
    • }