Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void combination(const char *str, int start, int end, int m, char *cmb, int m_exist){
- if(m==0){
- cout<<"{";
- for(int i=m_exist-1; i>0; i--)
- cout<<cmb[i]<<", ";
- cout<<cmb[0]<<"}"<<endl;
- return;
- }
- for(int i=start; i<end; i++){
- cmb[m-1]=str[i];
- combination(str,i+1,end,m-1,cmb,m_exist);
- }
- }
- int main() {
- string str("12345");
- int N=str.size();
- int M=2; //change M whatever you want
- char *cmb=new char[M];
- combination(str.c_str(), 0, N, M, cmb, M);
- delete [] cmb;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement