Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************************************/
- /** 20140514 Classwork_0507 Question 3 Answer **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/05/14 am.05:05 **/
- /***********************************************/
- #include <stdio.h>
- #include <stdlib.h>
- void cut_cake(int, int);
- void main()
- {
- while(1)
- {
- int cut = 0;
- printf("Enter a number of knives under: ");
- scanf("%d", &cut);
- if(cut == -1)
- {
- break;
- }
- int count = 1;
- cut_cake(cut, count);
- }
- printf("Your Program is exiting ..\n");
- system("pause");
- system("cls");
- }
- void cut_cake(int cut, int count)
- {
- if(cut != 0)
- {
- count += cut;
- cut -= 1;
- cut_cake(cut, count);
- }
- else if(cut == 0)
- {
- printf("You get %2d piece of cake.\n\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment