RenHao

e-Tutor_3

Sep 21st, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(int argc, const char * argv[])
  4. {
  5.     int Quotient = 0, Remainer = 0 , n = 0, m = 0, result = 0, temp = 0;
  6.     char PurchasedSticks[10] , NeededSticks[10];
  7.    
  8.     while(1)
  9.     {
  10.         scanf("%s",PurchasedSticks);
  11.         scanf("%s",NeededSticks);
  12.         n = atoi(PurchasedSticks);
  13.         m = atoi(NeededSticks);
  14.        
  15.         if( n == 0 )  return 0;   //  End of input
  16.         else
  17.         {
  18.             Quotient = n / m;
  19.             Remainer = n % m;
  20.             result   = Quotient;
  21.             while( (temp = Quotient + Remainer) >= m )
  22.             {
  23.                 Quotient = temp / m;
  24.                 Remainer = temp % m;
  25.                 result +=  Quotient;
  26.             }
  27.             printf("%d\n",result);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment