Advertisement
dllbridge

Books

Mar 17th, 2023
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3.  
  4.  
  5.  
  6. ///////////////////////////////////////
  7. int main()
  8. {
  9.    
  10.     int   in_stack =    0,
  11.         total_cost =    0,
  12.          book_cost = 1000,       
  13.        count_books       ;
  14.    
  15.    
  16.    
  17.     printf("Enter count of books: ");
  18.     scanf("\n%d", &count_books);
  19.    
  20.     int i = 1;
  21.    
  22.     if(count_books < 0) printf("Wrong number.");
  23.     else
  24.     {
  25.         for(; i <= count_books; i++)
  26.         {
  27.                        
  28.             total_cost  += book_cost;
  29.             book_cost   -=  55;
  30.             in_stack    ++    ;
  31.        
  32.             if(in_stack ==   7)
  33.             {
  34.                book_cost = 1000;
  35.                in_stack  =    0;
  36.             }
  37.         }
  38.        
  39.         printf("%2i books = %d\n", i-1, total_cost);
  40.     }  
  41.  
  42. return 0;
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. /*
  57.  
  58. #include <stdio.h>
  59.  
  60. int main() {
  61.     int count_books;
  62.     int total_cost = 0, book_cost = 1000, in_stack = 0;
  63.     printf("Enter count of books: ");
  64.     scanf("\n%d", &count_books);
  65.    
  66.     if (count_books < 0) {printf("Wrong number.");}
  67.     else {
  68.         for (int i = 0; i <= count_books; i++) {
  69.             printf("%i books = %d\n",i, total_cost);
  70.             total_cost += book_cost;
  71.             book_cost -= 55;
  72.             in_stack++;
  73.             if (in_stack == 7) {
  74.                 book_cost = 1000;
  75.                 in_stack = 0;
  76.             }
  77.         }
  78.     }
  79.     return 0;
  80. }
  81.  
  82. */
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement