/* Problem 3--Ruler This was intended to be the easiest problem of the set. It is mostly self-explanatory. */ #include #include FILE *in, *out; int main (int argc, char **argv); int main (int argc, char **argv) { int size, i, t; in = fopen ("prob3.in","r"); out = fopen ("prob3.out","w"); while (fscanf (in,"%d",&size),size>0) { /* read in the case */ for (i=1; i <=size; i++) { t = i; while (1) { fprintf (out,"-"); /* print -'s until a 1 is found in the binary */ if (t%2==1) break; /* representation */ t /= 2; } fprintf (out,"\n"); } fprintf (out,"\n"); } fclose (in); fclose (out); return EXIT_SUCCESS; }