Pagini recente » Cod sursa (job #2416875) | Cod sursa (job #2358559) | Cod sursa (job #2266107) | Cod sursa (job #1426578) | Cod sursa (job #1219309)
#include <stdio.h>
#include <stdlib.h>
#define FIN "fractal.in"
#define FOUT "fractal.out"
#define PATRAT(t) (t*t)
int fractal(int ord, int x, int y){
int m;
if(ord < 0){
return 0;
}
m = 1<<ord;
if(x <= m && y <= m){
return fractal(ord-1, y, x);
} else if ( x > m && y <= m) {
return PATRAT(m) + fractal(ord-1, x-m, y);
} else if ( x > m && y > m) {
return 2*PATRAT(m) + fractal(ord-1, x-m, y-m);
} return 3*PATRAT(m) + fractal(ord-1, 2*m-y+1, m-x+1);
}
int main(){
FILE *in, *out;
int ord, x, y;
in = fopen(FIN, "rt");
out = fopen(FOUT, "wt");
fscanf(in, "%d%d%d", &ord, &x, &y);
fprintf(out, "%d", fractal(ord,x,y));
return 0;
}