#include #include FILE *fp; int main(int argc, char *argv[]) { /* Generator program to create (some) test data. NB. It is not the case that all test data comes from this program, i.e. you must not write a solution that is only optimal only for this source. */ long i = 0, j = 13, r = 0, a1 = 99; long number, seed, step=100, mean = 0, varn=100; float xx = 0.0, a2, a3, a4, a[100], p, q, small, big; if (argc < 3) { printf("usage: %s n seed [m]\n", argv[0]); exit(0); } number = atol(argv[1]); seed = atol(argv[2]); if( seed <= 0 ) seed = 1231; srandom(seed); /* set seed for prng */ if ((fp = fopen("rand","w")) == NULL) { printf("File not opened rand.\n"); exit(0); } for(i=0; i < number; i++) { /* mean wanders randomly */ mean = mean + (random() % (2*step+1) - step); if( random() % 1000 == 17 ) /* i.e. 1 in 1000 */ { if( random() % 10 > 7 ) /* i.e. 2 in 10 */ step = step * 2; else if( random() % 10 > 7 ) step = step / 2; if( step < 10) step = 10; } varn = varn + (random() % 21 - 10); /* local variation */ if( varn < 1 ) varn = 100; else if( varn > 1000000 ) varn = 1000; xx = mean + (random() % 1000000)*varn/1000000.0; if( i== 0 ) { small = xx; big = xx; } else if( xx < small ) small = xx; else if( xx > big ) big = xx; fprintf( fp, "%f ", xx ); if ((i % 5) == 4) fprintf(fp,"\n"); if(i < 100) a[i] = xx; } fclose(fp); printf("--- %i random values, [%f, %f], written to rand ---\n", number, small, big); if(argc <= 3) r = 6; else r = atol(argv[3]); r = r < 1 ? 1 : r; i=-1; j=2*number; if(number > 0 && r<=100 && number<=100){ while(1==1){ if(i+r>number)break; /* zero marks for code like this! */ if(j+1==i+r && (i==0||q=i+r){ i++; j=i; p=a[i]; q=a[j]; continue; } j++; /* zero marks for code like this! */ if(a[j]>q) q = a[j]; if(a[j]