/* Problem 2--Snakes This should have been quite easy. Just draw the picture. */ #include #include int main (int argc, char **argv); void Process (int s); FILE *in, *out; int main (int argc, char **argv) { int s; in = fopen ("prob2.in","r"); out = fopen ("prob2.out","w"); while (1) { fscanf (in,"%d",&s); /* get size */ if (s==0) break; Process (s); } fclose (in); fclose (out); return EXIT_SUCCESS; } /* Process prints out the crest of the desired size */ void Process (int s) { int i, j; fprintf (out,"/"); for (i=0; i < s; i++) fprintf (out,"-"); /* first horizontal row */ fprintf (out," "); for (i=0; i < s; i++) fprintf (out,"-"); fprintf (out,"\\\n"); for (i=0; i < s; i++) { /* first vertical row */ fprintf (out,"|"); for (j=0; j < 2*s+3; j++) fprintf (out," "); fprintf (out,"|\n"); } fprintf (out,"\\"); for (i=0; i < s; i++) fprintf (out,"-"); /* second horizontal row */ fprintf (out,"\\ /"); for (i=0; i < s; i++) fprintf (out,"-"); fprintf (out,"/\n"); for (i=0; i < s; i++) { /* second vertical row */ for (j=0; j < s+1; j++) fprintf (out," "); fprintf (out,"| |\n"); } fprintf (out," "); /* final horizontal row */ for (i=0; i < s; i++) fprintf (out,"-"); fprintf (out,"/ \\"); for (i=0; i < s; i++) fprintf (out,"-"); fprintf (out,"\n\n"); }