← C# from Scratch Lesson 9 of 39 · 10 XP

Operators

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

Arithmetic: + - * / and % (the remainder). With two ints, division is integer division: 7 / 2 == 3, 7 % 2 == 1.

Assignment: x += 5 is the same as x = x + 5; likewise -=, *=, /=, %=. x++ / x-- — increase / decrease by 1.

Comparison (gives a bool): == != < > <= >=.

Logical: && (and), || (or), ! (not). && and || are lazy (short-circuit): if the answer is clear from the left side, the right side isn't evaluated — obj != null && obj.Ok won't crash on null.

Precedence is as in maths: * / % before + -; when in doubt, use parentheses.

Task. Read a total number of seconds and print the time as h:mm:ss (minutes and seconds as two digits). For example, 3725 → 1:02:05. For a two-digit number, use the format {m:D2} in interpolation.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.