Linked Questions

Popular Questions

How to Count primitive operations of a while Loop

Asked by At

Counting only {+, -, *, /, //,%, >, <, ==,<=, >= } as basic operations, determine the exact number of basic operations that would be performed when the following code fragment is executed for the given values of n and t.

n = 5
t = 3
s = 0
i = 0
j = 0
x = n
while s < t:
    if x % 2 == 1:
        i = i + 1
    x = x // 2
    for k in xrange(n):
        s = s + 1
        j = j + i
print(j)

i Know the answer is 23 but i get 19 with this 6*n+1 equation

Related Questions