Home > Back-end >  Save the children!
Save the children!

Time:09-16

C language requirements to write the report, the problem: find all eligible "double-digit * three digits" double-digit ﹦ double-digit, each digit placeholder Numbers 1 to 9, do not contain 0, not repeat,
Although I also wrote but too... And then looking for help with writing, but I don't understand the algorithm design, more don't draw flowcharts, strives for the bosses guidance!
#include

#include
Int n=0;
Int right=0;
Void swap (int * a, int * b)
{

Int m;

M=* a;

*=* b;

* b=m;

}

Void perm (int the list [], int k, int m)

{

int i;

If (k & gt; M)

{
//determine whether meet the aa * aa=aa * aaa a is 1 to 9 without repeating
Int first=list [0] * 10 + list [1];
Int second=the list [2] [3] * 10 + list;
Int third=list [4] [5] * 10 + list;
Int forth=list [6] * 100 + list [7] [8] * 10 + list;
If (second==third first * * forth) {
for(i=0; I & lt;=m; I++)

Printf (" % d ", a list [I]);


printf("\n");
Right++;
}
N++;

}

The else

{

For (I=k; I & lt;=m; I++)

{

Swap (& amp; The list [k], & amp; The list [I]);

Perm (list, k + 1, m);

Swap (& amp; The list [k], & amp; The list [I]);

}

}

}

Int main ()

{

Int k;//the number of input natural number bai

Printf (" please input the number of consecutive natural number: ");

The scanf (" % d ", & amp; K); Int * list=(int *) malloc (k);

for (int i=0; I & lt; k; I + +)

{

The list [I]=I + 1;

}

//int the list []={1, 2, 3, 4, 5};

Perm (list, 0, k - 1);

Printf (" total: % d \ n ", n);
Printf (" right: % d \ n ", right);
return 0;

}

CodePudding user response:

https://bbs.csdn.net/topics/396858956 to see this post
  • Related