您所在的位置:Seago-Microsoft Windows>>Windows管理脚本>> 问题

问题

作者:monface 来源:新浪爱问 日期:2008-04-10 

1到10当中输出3个数,但是那输出的3 个数不能重复,请写出全排列 ,看能有多少组, 电脑问题网给出的最佳答案 数学上的全排列P(10,3)=10*9*8=720

全部的结果如下:
void main()
{
int a,b,c,count;
count=0;
for(a=1;a<=10;a )
for(b=1;b<=10;b )
for(c=1;c<=10;c )
{
if( a!=b && a!=c && b!=c )
{
printf("%d\t%d\t%d\n",a,b,c);
count ;
}
}
printf("count=%d\n",count);
}

其他回答   #include <iostream>
using namespace std;
void main()
{
int a,b,c,count;
count=0;
for(a=1;a<=10;a )
for(b=1;b<=10;b )
for(c=1;c<=10;c )
{
if( a!=b && a!=c && b!=c )
{
cout<<a<<" "<<b<<" "<<c<<" ";
count ;
if(count==0)//控制每行输出10个数字
cout<<endl;
}
}
cout<<"全部的组合数为:"<<count<<endl;
}