Home > Software engineering >  C simple algorithm
C simple algorithm

Time:09-23

Suppose you have a m * n a procession of information, each unit and become a * b category information,

It is 3 * 3, for example, every small piece is 3 * 3
As shown in figure
The original
* * *
* * *
* * *
After the
* * * * * * * * *
* * * * * * * * *
* * * * * * * * *

* * * * * * * * *
* * * * * * * * *
* * * * * * * * *

* * * * * * * * *
* * * * * * * * *
* * * * * * * * *

CodePudding user response:

Fyi:
//input 1 
//output
//* *
//*
//* *
//enter 2
//output
//* * * *
//* *
//* * * *
//* *
//*
//* *
//* * * *
//* *
//* * * *
//input 3
//output
//* * * * * * * *
//* * * *
//* * * * * * * *
//* * * *
//* *
//* * * *
//* * * * * * * *
//* * * *
//* * * * * * * *
//* * * *
//* *
//* * * *
//* *
//*
//* *
//* * * *
//* *
//* * * *
//* * * * * * * *
//* * * *
//* * * * * * * *
//* * * *
//* *
//* * * *
//* * * * * * * *
//* * * *
//* * * * * * * *
//maximum 8
#include
Char m [6561] [6561].//==3 ^ 8
Cx, void fractalx (int cy, int int L) {
Int N, I;

If (1==L) {
Cx] m [cy] [='*';
Cx - m [cy - 1] [1]='*';
Cx + m [cy - 1] [1]='*';
Cx + m [cy + 1] [1]='*';
Cx - m [cy + 1] [1]='*';
} else {
N=1; for (i=0; iFractalx (cy, cx, L - 1);
Cx - fractalx (cy - N, N, L - 1);
Cx + fractalx (cy - N, N, L - 1);
Fractalx (cx + cy + N, N, L - 1);
Fractalx (cx - cy + N, N, L - 1);
}
}
Int main () {
Int L, N, I, y, x;

While (1) {
While (1) {
Printf (" \ nInput 1.. 8, 0 for the Exit: ");
The fflush (stdout);
If (1==the scanf (" % d ", & amp; L)) {
If (0 & lt;=L & amp; & L<=8) break;
} the else rewind (stdin);
}
If (0==L) break;
N=1; for (i=0; iFor (y=3280 - (N - 1)/2; Y<=3280 + (N - 1)/2; Y++) {
For (x=3280 - (N - 1)/2; x<=3280 + (N - 1)/2; X++) {
M [y] [x]=' ';
}
}
Fractalx (3280328 0, L);
For (y=3280 - (N - 1)/2; Y<=3280 + (N - 1)/2; Y++) {
For (x=3280 - (N - 1)/2; x<=3280 + (N - 1)/2; X++) {
Printf (" % c ", m [y] [x]).
}
printf("\n");
}
}
return 0;
}
  • Related