what purpuse this logic is used

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SrikanthBichala
    New Member
    • Oct 2010
    • 2

    what purpuse this logic is used

    1) int foo(int x)
    {
    if(x<=0)
    return 0;
    else
    return 1+foo(x/10);
    }

    a) What is the output of this logic for foo(12345)
    b) What purpose this logic is used
    c) If we give negative number what output will get. If u future enhance n find a bug, how u change the code to fix the bug n the remain work for negative n positive numbers.
  • Meetee
    Recognized Expert Contributor
    • Dec 2006
    • 928

    #2
    The purpose of this snippet is to show an example - recursion. Rest you can run the code and get the answers!

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Walk through the logic with pencil and paper. What do you get for foo(12345)? What do you get for foo(123)?

      Comment

      Working...