Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

void fun(int n) { Stack S; // Say it creates an empty stack S while (n > 0) { //

ID: 3556159 • Letter: V

Question

void fun(int n)

{

    Stack S; // Say it creates an empty stack S

    while (n > 0)

    {

      // This line pushes the value of n%2 to stack S

      push(&S, n%2);

      n = n/2;

    }

    // Run while Stack S is not empty

    while (!isEmpty(&S))

      printf("%d ", pop(&S)); // pop an element from S and print it

}

What does the above function do in general?

Prints binary representation of n in reverse order

Prints binary representation of n

C)

Prints the value of Logn

D)

Prints the value of Logn in reverse order

void fun(int n)

{

    Stack S; // Say it creates an empty stack S

    while (n > 0)

    {

      // This line pushes the value of n%2 to stack S

      push(&S, n%2);

      n = n/2;

    }

    // Run while Stack S is not empty

    while (!isEmpty(&S))

      printf("%d ", pop(&S)); // pop an element from S and print it

}

Explanation / Answer

Ans)

B) Prints binary representation of n.

ex: input 10- output 1010