gs gs122 Number Theory - Generating Partitions - Quiz No.1
gs gs122 Data Communication and Computer Network Quiz
This quiz belongs to book/course code gs gs122 Data Communication and Computer Network of gs organization. We have 268 quizzes available related to the book/course Data Communication and Computer Network. This quiz has a total of 10 multiple choice questions (MCQs) to prepare and belongs to topic Number Theory. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
#include<iostream> using namespace std; void printArray(int p[], int n) { for (int i = 0; i <= n-1; i++) cout << p[i] << " "; cout << endl; } void func1(int n) { int p[n]; int k = 0; p[k] = n; while (true) { printArray(p, k+1); int rem_val = 0; while (k >= 0 && p[k] == 1) { rem_val += p[k]; k--; } if (k < 0) return; p[k]--; rem_val++; while (rem_val > p[k]) { p[k+1] = p[k]; rem_val = rem_val - p[k]; k++; } p[k+1] = rem_val; k++; } } int main() { int n; cin>>n; func1(n); 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; }
3 2 1 1 1 1
1 1 1 2 1 3
1 1 1 1 2 3
3 1 2 1 1 1
#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; }