adplus-dvertising

Welcome to the Recursion MCQs Page

Dive deep into the fascinating world of Recursion with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Recursion, a crucial aspect of Data Structures and Algorithms. In this section, you will encounter a diverse range of MCQs that cover various aspects of Recursion, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Data Structures and Algorithms.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Recursion. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Data Structures and Algorithms.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Recursion. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Recursion MCQs | Page 11 of 18

Q101.
Consider the following iterative implementation to find the sum of digits of a number:
Which of the following lines should be inserted to complete thebelow code?
#include<stdio.h>
int sum_of_digits(int n)
{
      int sm = 0;
      while(n != 0)
      {
          _________;
          n /= 10;
      }
      return sm;
}
int main()
{
      int n = 1234;
      int ans = sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

Discuss
Answer: (b).sm += n%10
Q102.
What is the output of the following code?
#include<stdio.h>
int sum_of_digits(int n)
{
      int sm = 0;
      while(n != 0)
      {
          sm += n%10;
          n /= 10;
      }
      return sm;
}
int main()
{
      int n = 1234;
      int ans = sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

a.

1

b.

3

c.

7

d.

10

Discuss
Answer: (d).10
Q103.
Consider the following recursive implementation to find the sum of digits of number:
Which of the following lines should be inserted to complete thebelow code?
#include<stdio.h>
int recursive_sum_of_digits(int n)
{
      if(n == 0)
        return 0;
      return _________;
}
int main()
{
      int n = 1201;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

Discuss
Answer: (c).(n % 10) + recursive_sum_of_digits(n / 10)
Q104.
What is the output of the following code?
#include<stdio.h>
int recursive_sum_of_digits(int n)
{
      if(n == 0)
        return 0;
      return n % 10 + recursive_sum_of_digits(n/10);
}
int main()
{
      int n = 1234321;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}
Discuss
Answer: (b).16
Q105.
How many times is the function recursive_sum_of_digits() called when the following code is executed?
#include<stdio.h>
int recursive_sum_of_digits(int n)
{
      if(n == 0)
        return 0;
      return n % 10 + recursive_sum_of_digits(n/10);
}
int main()
{
      int n = 1201;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}

a.

6

b.

7

c.

8

d.

9

Discuss
Answer: (c).8
Q106.
You have to find the sum of digits of a number given that the number is always greater than 0. Which of the following base cases can replace the base case for the below code?
#include<stdio.h>
int recursive_sum_of_digits(int n)
{
      if(n == 0)
        return 0;
      return n % 10 + recursive_sum_of_digits(n/10);
}
int main()
{
      int n = 1201;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}
Discuss
Answer: (d).none of the mentioned
Q107.
What is the output of the following code?
#include<stdio.h>
int recursive_sum_of_digits(int n)
{
      if(n == 0)
        return 0;
      return n % 10 + recursive_sum_of_digits(n/10);
}
int main()
{
      int n = 10000;
      int ans = recursive_sum_of_digits(n);
      printf("%d",ans);
      return 0;
}
Discuss
Answer: (b).1
Q108.
What is the output of the following code?
#include<stdio.h>
int cnt =0;
int my_function(int n, int sm)
{
      int i, tmp_sm;
      for(i=1;i<=n;i++)
      {
          tmp_sm = recursive_sum_of_digits(i);
          if(tmp_sm == sm)
            cnt++;
      }
      return cnt;
}
int recursive_sum_of_digits(int n)
{
      if(n == 0)
        return 0;
      return n % 10 + recursive_sum_of_digits(n/10);
}
int main()
{
      int n = 20, sum = 3;
      int ans = my_function(n,sum);
      printf("%d",ans);
      return 0;
}

a.

0

b.

1

c.

2

d.

3

Discuss
Answer: (c).2
Q109.
Consider the following iterative implementation used to reverse a string:
Which of the following lines should be inserted to complete thebelow code?
#include<stdio.h>
#include<string.h>
void reverse_string(char *s)
{
     int len = strlen(s);
     int i,j;
     i=0;
     j=len-1;
     while(______)
     {
         char tmp = s[i];
         s[i] = s[j];
         s[j] = tmp;
         i++;
         j--;
     }
}
Discuss
Answer: (d).i < j
Q110.
Which of the following is the binary representation of 100?
Discuss
Answer: (c).1100100

Suggested Topics

Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!