Holey_yan

20140514_KUAS_VisualC++_Classwork_0507_Question_3_Answer

May 14th, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. /***********************************************/
  2. /** 20140514 Classwork_0507 Question 3 Answer **/
  3. /** Maker  : Yan                              **/
  4. /** E-Mail : [email protected]            **/
  5. /** Date   : 2014/05/14 am.05:05              **/
  6. /***********************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. void cut_cake(int, int);
  12.  
  13. void main()
  14. {
  15.     while(1)
  16.     {
  17.         int cut = 0;
  18.         printf("Enter a number of knives under: ");
  19.         scanf("%d", &cut);
  20.         if(cut == -1)
  21.         {
  22.             break;
  23.         }
  24.  
  25.         int count = 1;
  26.         cut_cake(cut, count);
  27.     }
  28.     printf("Your Program is exiting ..\n");
  29.     system("pause");
  30.     system("cls");
  31. }
  32.  
  33. void cut_cake(int cut, int count)
  34. {
  35.     if(cut != 0)
  36.     {
  37.         count += cut;
  38.         cut -= 1;
  39.         cut_cake(cut, count);
  40.     }
  41.     else if(cut == 0)
  42.     {
  43.         printf("You get %2d piece of cake.\n\n");
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment