1

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.

1 Answers1

1

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).

iostream007
  • 4,529