ahmedraza

collatz

Nov 18th, 2016
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.29 KB | None | 0 0
  1. int coll (int a,int c)
  2. {
  3.     //if a is odd number
  4.     if(a%2==1 && a!=1)
  5.     {
  6.         coll ((3*a)+1, c++);
  7.     }
  8.      //If a is even number
  9.     else if(a%2==0 && a!=1)
  10.     {
  11.         coll (a/2, c++);
  12.     }
  13.    
  14.     //Base case returns the value of c
  15.    
  16.     else
  17.         return c;
  18. }
Add Comment
Please, Sign In to add comment