组合数

#include <iostream>
#include <string.h>
using namespace std;


int main()
{    
    char s[]="abcdefgh";

    int i,j,k;   
     int b;
     b=strlen(s);//get the length;
     for(i=0;i<=b;i++)//make a loop to find all the different elements by define i!=j and so on;
     {
        for(j=i+1;j<=b-1;j++)
        { 
           for(k=j+1;k<=b-1;k++)//notice that it couldn't greater than b-1,or it will be NULL when k is equal to strlen(s);
            {
               cout<<"the three elements set "<<"{"<<s[i]<<","<<s[j]<<","<<s[k]<<"}";     //output the sets          
                      cout<<endl;
                         }
                      }
                  }
   system ("pause");
   return 0;
}                  

//sample output :
         the three elements set {a,b,c}
the three elements set {a,b,d}
the three elements set {a,b,e}
the three elements set {a,b,f}
the three elements set {a,b,g}
the three elements set {a,b,h}
the three elements set {a,c,d}
the three elements set {a,c,e}
the three elements set {a,c,f}
the three elements set {a,c,g}
the three elements set {a,c,h}
the three elements set {a,d,e}
the three elements set {a,d,f}
the three elements set {a,d,g}
the three elements set {a,d,h}
the three elements set {a,e,f}
the three elements set {a,e,g}
the three elements set {a,e,h}
the three elements set {a,f,g}
the three elements set {a,f,h}
the three elements set {a,g,h}
the three elements set {b,c,d}
the three elements set {b,c,e}
the three elements set {b,c,f}
the three elements set {b,c,g}
the three elements set {b,c,h}
the three elements set {b,d,e}
the three elements set {b,d,f}
the three elements set {b,d,g}
the three elements set {b,d,h}
the three elements set {b,e,f}
the three elements set {b,e,g}
the three elements set {b,e,h}
the three elements set {b,f,g}
the three elements set {b,f,h}
the three elements set {b,g,h}
the three elements set {c,d,e}
the three elements set {c,d,f}
the three elements set {c,d,g}
the three elements set {c,d,h}
the three elements set {c,e,f}
the three elements set {c,e,g}
the three elements set {c,e,h}
the three elements set {c,f,g}
the three elements set {c,f,h}
the three elements set {c,g,h}
the three elements set {d,e,f}
the three elements set {d,e,g}
the three elements set {d,e,h}
the three elements set {d,f,g}
the three elements set {d,f,h}
the three elements set {d,g,h}
the three elements set {e,f,g}
the three elements set {e,f,h}
the three elements set {e,g,h}
the three elements set {f,g,h}
Press any key to continue . . .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值