Which Of The Following Correctly Represents The Code To Print #1172
Which of the following correctly represents the code to print partitions of a number?
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.
Which of the following correctly represents the code to print partitions of a number?
#include<iostream> using namespace std; int print[200]; void partitn(int n,int k,int idx) { if(n==0) { for(int i=0;i<idx;i++) cout<<print[i]<<" "; cout<<endl; return ; } for(int i=k;i>0;i--) { if(i>n)continue; print[idx]=i; partitn(n-i,i,idx+1); } } int main() { int n; cin>>n; partitn(n,n,0); return 0; }
#include<iostream> using namespace std; int print[200]; void partitn(int n,int k,int idx) { if(n==0) { for(int i=0;i<idx;i++) cout<<print[i]<<" "; cout<<endl; return ; } for(int i=k;i>0;i--) { if(i>n)continue; print[idx]=i; partitn(n-i,i,idx+1); } } int main() { int n; cin>>n; partitn(n,0,0); return 0; }
#include<iostream> using namespace std; int print[200]; void partitn(int n,int k,int idx) { if(n==0) { for(int i=0;i<idx;i++) cout<<print[i]<<" "; cout<<endl; return ; } for(int i=k;i>0;i--) { print[idx]=i; partitn(n-i,i,idx+1); } } int main() { int n; cin>>n; partitn(n,0,0); return 0; }
#include<iostream> using namespace std; int print[200]; void partitn(int n,int k,int idx) { if(n==0) { for(int i=0;i<idx;i++) cout<<print[i]<<" "; cout<<endl; return ; } for(int i=k;i>0;i--) { print[idx]=i; partitn(n-i,i,idx+1); } } int main() { int n; cin>>n; partitn(n,n,0); return 0; }
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