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