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;
}
#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;
}
A.
3
2 1
1 1 1
B.
1 1 1
2 1
3
C.
1 1 1
1 2
3
D.
3
1 2
1 1 1
Answer: Option A
Join The Discussion