What Will Be The Output Of The Following Codep Pre Langc #1171
What will be the output of the following code?</p> <pre><code class="language-c"> #include<iostream> using namespace std; int list[200]; void func(int n, int m = 0) { int i; if(n == 0) { for(i = 0; i < m; ++i) printf("%d ", list[i]); printf("\n"); return; } for(i = n; i > 0; --i) { if(m == 0 || i <= list[m - 1]) { list[m] = i; func(n - i, m + 1); } } } int main() { int n=3; func(n,0); return 0; }</code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs122 Data Communication and Computer Network. It can also be found in gs gs122 Number Theory - Generating Partitions - Quiz No.1.
What will be the output of the following code?
#include<iostream> using namespace std; int list[200]; void func(int n, int m = 0) { int i; if(n == 0) { for(i = 0; i < m; ++i) printf("%d ", list[i]); printf("\n"); return; } for(i = n; i > 0; --i) { if(m == 0 || i <= list[m - 1]) { list[m] = i; func(n - i, m + 1); } } } int main() { int n=3; func(n,0); return 0; }
3 2 1 1 1 1
1 1 1 2 1 3
1 1 1 1 2 3
3 1 2 1 1 1
Similar question(s) are as followings:
Online Quizzes of gs122 Data Communication and Computer Network
Sorting - Insertion Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - Insertion Sort - Quiz No.3
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - LSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.1
gs gs122 Data Communication and Computer Network
Online Quizzes
Sorting - MSD Radix Sort - Quiz No.2
gs gs122 Data Communication and Computer Network
Online Quizzes