/* From: "COMPUTATIONAL PHYSICS, 2nd Ed" by RH Landau, MJ Paez, and CC Bordeianu Copyright Wiley-VCH, 2007. Electronic Materials copyright: R Landau, Oregon State Univ, 2007; MJ Paez, Univ Antioquia, 2007; & CC Bordeianu, Univ Bucharest, 2007 Support by National Science Foundation */ // column.c: Correlated ballistic deposition to form fractalcomment: #include #include // if you don't have drand48 uncomment the following two lines #define drand48 1.0/RAND_MAX*rand #define srand48 srand #define max 100000 // number of iterations #define npoints 200 // no. of open spaces #define seed 68111 // seed for number generator main() { int i, hit[200], dist, r, x, y, oldx, oldy; double pp, prob; FILE *output; output = fopen("column.dat","w"); // seed random generator srand48(seed); for (i=0; i0) && (r<(npoints-1))) { if ((hit[r] >= hit[r-1]) && (hit[r] >= hit[r+1])) hit[r]++; else if (hit[r-1] > hit[r+1]) hit[r] = hit[r-1]; else hit[r] = hit[r+1]; oldx = r; oldy = hit[r]; fprintf(output, "%d\t%d\n", r, hit[r]); } } } printf("data stored in column.dat\n"); fclose(output); }