Question

What is the value of n and counter when the code below is executed? n =...

What is the value of n and counter when the code below is executed?

n = 256; 
counter = 1; 
while n ~= 1 
 if rem(counter,2) == 0 
 n = n/2; 
 else 
 n = n/4; 
 end 
counter = counter + 1 ;
end

a.

n=1;

counter = 6

b.

n=5;

counter = 6;

c.

n=6;

counter = 256;

d.

n=256

counter = 6

e.

n=128;

counter=64;

Homework Answers

Answer #1

Hello the answer for given question is

A) n = 1

counter = 6

Explanation

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
What is the value of n and counter when the code below is executed? n =...
What is the value of n and counter when the code below is executed? n = 256; counter = 1; while n ~= 1 if rem(counter,2) == 0 n = n/2; else n = n/4; end counter = counter + 1 ; end a. n=1; counter = 6 b. n=5; counter = 6; c. n=6; counter = 256; d. n=256 counter = 6 e. n=128; counter=64;
What is the value of n and counter when the code below is executed? n =...
What is the value of n and counter when the code below is executed? n = 256; counter = 1; while n ~= 1 if rem(counter,2) == 0 n = n/2; else n = n/4; end counter = counter + 1 ; end a. n=1; counter = 6 b. n=5; counter = 6; c. n=6; counter = 256; d. n=256 counter = 6 e. n=128; counter=64;
Below is C code and Python code for an algorithm. C code: void foo( int n,...
Below is C code and Python code for an algorithm. C code: void foo( int n, int A, int B, int C ) { if( n==1 ) { printf("%d to %d\n",A,B); return; } foo( n-1, A, C, B ); printf("%d to %d\n",A,B); foo( n-1, B, C, A ); Python code: def foo(n , A, B, C): if n==1: print A, "to", B return foo(n-1, A, C, B) print A, "to", B foo(n-1, B, C, A) Let Hn be the number...
Take a look at the code below. What is the problem with the code? Change the...
Take a look at the code below. What is the problem with the code? Change the code so that it will run properly. (10 points) i = -6 # Code the while loop while i != 0 :     print("Output 1")     if i>0 :           print("Output 2")     else :           print("Output 3")    print(offset)
1. How many times the loop below will be executed? What is the value of variable...
1. How many times the loop below will be executed? What is the value of variable counter after the loop? counter = 1 while counter < 7: counter+=2 print(counter) 2. An integer is stored in a variable MyInt. Write the Python if statement to test if MyInt is even number or odd number, and print a message to show “It is even number.” or “It is an odd number”. 3. Complete the python below that asks user to enter the...
The code segment in Listing 1, when completed and executed, creates nums, an uninitialized 4-integer array....
The code segment in Listing 1, when completed and executed, creates nums, an uninitialized 4-integer array. It stores 4 and 5 as the first and second elements, respectively, of the array. It adds the first and second elements of the array and stores their sum as the third element of the nums. It prints the third element of nums. It then adds the second and third elements of the array and stores their sum as the fourth element of nums....
What is the condition in "if" statement in the piece of code below to produce the...
What is the condition in "if" statement in the piece of code below to produce the following output 4 9 14 19 end int count = 1; while (count <= 5) { if (_____) System.out.print(5*count - 1 + " "); else System.out.print("end"); count++; } count != 5 count = 5 count < 5 !(count == 5) count > 5
Machine Language - 1. Which of the following assembly code represents the high-level Java code below?...
Machine Language - 1. Which of the following assembly code represents the high-level Java code below? int x; int i = 5; if (i < 0) x = -1; else x = 1; @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JGE @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END...
In Java 1. What will be the value of x after the following section of code...
In Java 1. What will be the value of x after the following section of code executes: int x = 3; if (x > 3)     x = x – 2; else     x = x + 2; A. 1 B.3    C.5              D.7 2. What will be the value of y after the following section of code executes: int y = 5, z = 3; if (y > 4){      z = 2;      y = y – 1;...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n ==...
QUESTION 1 For the following recursive function, find f(5): int f(int n) { if (n == 0)    return 0; else    return n * f(n - 1); } A. 120 B. 60 C. 1 D. 0 10 points    QUESTION 2 Which of the following statements could describe the general (recursive) case of a recursive algorithm? In the following recursive function, which line(s) represent the general (recursive) case? void PrintIt(int n ) // line 1 { // line 2...