[CODE]#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;
void display(int * num, int length)
{
for(int i = 0; i<length; i++)
cout<<num[i]<<"
";
cout<<endl;
}
int createValue(int * num, int length)
{
int value = 0;
int digit = 0;
int pow = 0;;
int l = length;
while(length != 0)
{
digit = num[l - length];
pow = 1;
for(int i = 1; i<length; i++)
{
pow = pow * 10;
}
value = value + digit*pow;
length--;
}
return value;
}
bool check(int * num, int length)
{
for(int i = 2; i<length; i++)
{
int value = createValue(num, i);
if(value % i != 0)
return false;
}
return true;
}
int main()
{
const int LENGTH = 9;
//declare a integer array with length 9
int num[LENGTH];
//initialize it
for(int i = 0; i<LENGTH; i++)
num[i] = i+1;
//check first combination
if(check(num, LENGTH))
display(num, LENGTH);
while(next_permutation(num, num+LENGTH-1))
{
if(check(num, LENGTH))
display(num, LENGTH);
}
system("pause");
return 0;
}[/CODE]