1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C programming question

  1. Aug 29, 2011 #1
    1. The problem statement, all variables and given/known data

    Simulate the following program

    #include <stdio.h>

    int xxx (int n)
    {
    int count;

    count = 0;

    while ( n >=2)
    {
    n = n/2;
    ++count;
    }

    return count;
    }

    main()
    {
    printf( "xxx(17)=%d\n", xxx(17) );
    }
    2. Relevant equations



    3. The attempt at a solution

    Is this correct?

    n, count
    17 0
    8 1
    4 2
    2 3
    1 4

    Return 4, 4 gets printed
     
  2. jcsd
  3. Aug 29, 2011 #2

    lewando

    User Avatar
    Gold Member

    Looks right.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: C programming question
  1. C programming question (Replies: 7)

  2. C programming question (Replies: 22)

  3. C programming question (Replies: 2)

  4. C programming question (Replies: 2)

  5. C programming question (Replies: 4)

Loading...