• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top | MCQs on Recursion Algorithm with Answers | Question 27

What is the output of the following program? 

C++
#include <stdio.h>

void print(int n, int j)
{
    if (j >= n)
        return;
    if (n - j > 0 && n - j >= j)
       printf("%d %d\n", j, n-j);
   print(n, j+1);
}

int main()
{
    int n = 8;
    print(n, 1);
}

(A)

1 7
2 6
3 5
4 4
4 4

(B)

1 7
2 6
3 5
4 4

(C)

1 7
2 6
3 5
 

(D)

1 2
3 4
5 6
7 8

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments