Python to C

The questions below are due on Sunday September 20, 2026; 11:59:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Back to Exercises

Consider this mystery function below that is written in Python. Rewrite it in C.

//takes in two integers num and base
def f_2(num, base):
    total = 0
    negative = num<0
    num = abs(num)
    while num>0:
        val = num%base
        total = base*total + val
        num = int((num-val)/base)
    if negative:
        return -total
    else:
        return total

Back to Exercises