Consider the following algorithm assume N to be a positive i

Consider the following algorithm; assume N to be a positive integer.

          1. X ? 0

          2. Y ? 0

          3. WHILE (X < N)

                    a. X ? X+2

                    b. Y ? Y+X

          4. Y ? Y/N

What will this algorithm compute when N = 2? N = 5?

Solution

when N = 2

X E (0 , 2)

X --> X+2

=> X E (2 , 4)

Y>0

Y --> Y + X

=> Y E (2 , Y+4)

Y --> Y/N

=> Y E ( (2)/2 , (Y+4)/2 )

=> Y E (1 , (Y/2+2))

when N = 5

X E (0 , 5)

X --> X+2

=> X E (2 , 7)

Y --> Y+X

=> Y E (2 , Y+7)

Y --> Y/N

Y E (2/5 , (Y/5+7/5))

Consider the following algorithm; assume N to be a positive integer. 1. X ? 0 2. Y ? 0 3. WHILE (X < N) a. X ? X+2 b. Y ? Y+X 4. Y ? Y/N What will this algor

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site