Electronic clock 2:

The electronic clock shows the time in the h:mm:ss format, that is, the number of hours is recorded first, then the required two-digit number of minutes, then the two-digit number of seconds. The number of minutes and seconds, if necessary, are supplemented to two digits with zeros.

n seconds have passed since the beginning of the day. Output what the clock will show. Example: input - 3602, output - 1:00:02 You need to solve something like this with the help of a div, mod ... which I just don’t really understand, the solution can be written in C ++ or C #.

// I have already solved the first task of this type: Electronic clock 1:

Given the number n . n minutes have passed since the beginning of the day. Determine how many hours and minutes the electronic clock will show at that moment. The program should display two numbers: the number of hours (from 0 to 23) and the number of minutes (from 0 to 59). Note that the number n can be more than the number of minutes in a day.

  var a, b, n:longint; begin readln(n); a:=(n div 60)mod 24; b:=n mod 60; writeln(a,' ',b); end. 

This is how the first version is solved, and how the second?

    5 answers 5

    Damn, it's arithmetic! 3 class !!! Remember the integer division:

     7 : 2 = 3 (остаток: 1) 7 div 2 = 3 (результат) 7 mod 2 = 1 (остаток) 125 div 60 = 2 125 mod 60 = 5 125 секунд = 2*60 секунд + 5 секунд = 2 минуты 5 секунд 1 час = 60 минут = 60*60 секунд = 3600 секунд 3752 div 3600 = 1 3752 mod 3600 = 152 3752 секунды = 1 час + 152 секунды 152 div 60 = 2 152 mod 60 = 32 152 секунды = 2 минуты + 32 секунды 3752 секунды = 1 час + 152 секунды = 1 час + 2 минуты + 32 секунды 

    Understand this, then take the leading zeros.

    • thanks, and how to add zeros if necessary? But it turned out like this: program e2; var n, h, mm, ss: longint; begin readln (n); h: = n; mm: = n; ss: = n; h: = n div 3600; mm: = (n mod 3600) div 60; ss: = n mod 60; writeln ('', h, ':', mm, ':', ss); end. - xHunter
    • One way is to check the number if it is less than 10. And also, either translate numbers into strings or manipulate the output. You can also see the function Format () <br> var <br> .... h_str, mm_str, ss_str, out_str: string; begin <br> .... str (h, h_str); <br> str (mm, mm_str); <br> str (ss, ss_str); <br> out_str: = h_str; <br> if mm <10 then out_str: = out_str + ': 0' + mm_str <br> else <br> out_str: = out_str + ':' + mm_str; <br> if ss <10 then out_str: = out_str + ': 0' + ss_str <br> else <br> out_str: = out_str + ':' + ss_str; <br> writeln (out_str); <br> end. - toxicdream
     var n: integer; h, m, s: integer; begin readln(n); h := (n mod (3600*24)) div 3600; m := (n mod 3600) div 60; s := (n mod 60); write(h, ':', m div 10, m mod 10, ':', s div 10, s mod 10); end. 
       var a, b,c, n:longint; begin readln(n); a:=((n div 60) div 60 )mod 24; b:=(n div 60)mod 60; c:=n mod 60; writeln(a,' ',b,' ',c); end. 
         var a,b,c,n: longint; begin Read (n); a:=n div 3600 mod 24; b:=n div 60 mod 60; c:= n mod 60; if (b<9) and (c<9) then write (a,':0',b,':0',c); if (b>9) and (c<9) then write (a,':',b,':0',c); if (b>9) and (c>9) then write (a,':',b,':',c); if (b<9) and (c>9) then write (a,':0',b,':',c); end. 

          n = int (input ())

          h = ((n // 60) // 60)% 24

          m = n // 60% 60

          m1 = str (m // 10)

          m2 = str (m% 10)

          m = m1 + m2

          s = n% 60

          s1 = str (s // 10)

          s2 = str (s% 10)

          s = s1 + s2

          print (h, m, s, sep = ':')