Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. void print_for (int n, FILE *out)
  3. {
  4.  
  5.  
  6.     int nbSheets = (n/4);
  7.     if( (n%4) != 0)
  8.         nbSheets++;
  9.  
  10.     int sup=nbSheets*4,inf=1,i;
  11.  
  12.  
  13.  
  14.     fprintf(out,"Printing order for %d pages\n", n);
  15.  
  16.     for(i = 0; i < nbSheets; i++)
  17.     {
  18.  
  19.         fprintf(out, "Sheet %d, front: ", i+1);
  20.         if(sup > n)
  21.             fprintf(out, "Blank");
  22.         else
  23.             fprintf(out, "%d",sup);
  24.         fprintf(out, ", %d\n",inf);
  25.  
  26.         sup--;
  27.         inf++;
  28.  
  29.         if(inf > n)
  30.             break;
  31.         fprintf(out, "Sheet %d, back: ", i+1);
  32.         fprintf(out, "%d, ",inf);
  33.  
  34.         if(sup > n)
  35.             fprintf(out, "Blank");
  36.         else
  37.             fprintf(out, "%d",sup);
  38.         fprintf(out, "\n");
  39.         sup--;
  40.         inf++;
  41.  
  42.     }
  43.  
  44. }
  45. int main ()
  46. {
  47.     int n;
  48.     FILE *in = fopen("enum.in", "r");
  49.     if(!in)
  50.         return 1;
  51.     FILE *out = fopen("enum.out", "w");
  52.     if(!out)
  53.         return 1;
  54.  
  55.     while(1){
  56.         fscanf(in, "%d\n",&n);
  57.         if(n == 0)
  58.             break;
  59.         print_for (n,out);
  60.     }
  61.  
  62.     fclose (out);
  63.     fclose (in);
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement