Network-Layer
May 5, 2024Question 4430 – Communication
May 5, 2024Question 7885 – Programming
Consider the following program written in pseudo-code. Assume that x and y are integers.
Count (x, y) { if (y != 1) { if (x != 1) { print("*") ; Count (x/2, y) ; } else { y = y - 1 ; Count (1024, y) ; } } }
The number of times that the print statement is executed by the call Count(1024, 1024) is ______.
Correct Answer: A
Question 7 Explanation:
#include
int count=0;
Count(x,y){
if(y!=1){
if(x!=1){
printf(“*”);
count = count +1;
Count(x/2,y);
}
else{
y=y-1;
Count(1024,y);
}
}
}
int count=0;
Count(x,y){
if(y!=1){
if(x!=1){
printf(“*”);
count = count +1;
Count(x/2,y);
}
else{
y=y-1;
Count(1024,y);
}
}
}
void main()
{
Count(1024,1024);
printf(“\n%d\n”,count);
}
Count ( ) is called recursively for every (y = 1023) & for every y, Count ( ) is called (x = 10) times = 1023 × 10 = 10230
10230
10231
10232
10233