Consider the following program N 1000 b 2 a 0 n N while

Consider the following program: N = 1000 b = 2 a = 0 n = N while n > = b n = n/b a = a+1 print a (a) What value will the above program print? (b) What value would be printed if N were initialized to 1024*1024*1024 (instead of 1000)? (c) What function of N does the variable a compute?

Solution

a)

the value of a is 9
   Explaination:
       after each itteration in while the value of n is
       500   
       250   
       125   
       62
       31
       15
       7   
       3   
       1   
       so total 9 time its been divided ..

b)
  
If N is 1024*1024*1024 = 1073741824 = 2^30
   the value of a is 30
  

c)
It prints the number of time the given input is divided by 2
   the main heart of function is inside while where it checks if n is greater then b , if its ture
   then it divide by 2 and increments a by 1.

 Consider the following program: N = 1000 b = 2 a = 0 n = N while n > = b n = n/b a = a+1 print a (a) What value will the above program print? (b) What value

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site