Formula for difference between two numbers on a wall clock in clokwise direction

$\begingroup$

It's my first post in math.stackexchange.com. I got a necessity to find out the clockwise difference between two numbers on a wall clock. For example, difference between 12 and 1 is 1 where as the difference between 1 and 12 is 11. Actually what I need is number of clock wise steps required reach number b from number a on a clock. While writing an application, I struck writing this function.

Please help me. Thanks in advance.

$\endgroup$ 3

1 Answer

$\begingroup$

i am writing a C function

Code

 int clockstep(int a, int b){ int steps =0; if (a<=b) { steps = b-a; } else { steps = 12-b+a; } return steps }

means you take input from user than compare it if 1st $<=$ 2nd then simply (2nd-1st) is your answer otherwise do (12-2nd+1st).

$\endgroup$ 6

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like