As an overview, 123 in base 7 would be
in decimal, which is 66.
The number 7B in base 15 would be
in decimal, which is 116.
To convert a decimal number to another number system (i.e., the base),
you can use the method shown in the following figures (which show conversion
into binary):
Observe that to convert the integer, we divide the number by the base. The remainder gives the least significant digit of the converted number. The quotient from the first division is divided by the base again. The remainder gives the second least significant digit of the converted number. We repeat the procedure until the quotient becomes smaller than the base. When that happens, the conversion is completed. Hint: You may want to make the recursive call before printing a converted digit, because the first converted digit will be the least significant digit.
To fulfill the basic requirement of the lab, you will need to write a program that converts an input positive integer (in base 10) into other bases, which are also inputs by the user.
Notice the following:
The basic program should use the following prompts to get user input:
Please enter a positive integer in base 10: Please enter the target bases:
The sample output of the program is shown as follows,
lore 39 % ls Makefile lab05.c lore 40 % make gcc -o lab05.out lab05.c
lore 41 % ./lab05.out Please enter a positive integer in base 10: 161 Please enter the target bases: 2 13 9 The number in base 2 is: 10100001 The number in base 13 is: C5 The number in base 9 is: 188 lore 42 % ./lab05.out Please enter a positive integer in base 10: 1879 Please enter the target bases: 5 11 19 The number in base 5 is: 30004 The number in base 11 is: 1459 The number in base 19 is: 53H
When you are satisfied that your program works correctly ( or you run out of time ), please do the following.
Name your program as lab05.c.
turnin -c cs240=XXXX -p lab05 lab05
where XXXX represents your lab section number (number only!).
The turnin section should be as follows:
| Section | Time | TA |
| 0201 | Th 15:30-17:20 | Dan Zhang |
| 0301 | F 9:30-11:20 | Suli Xi |
| 0401 | F 13:30-15:20 | Youhan Fang |
| 0501 | Th 9:30-11:20 | J.C. Chin |
Make sure turnin reports that your project was submitted for grading.
turnin -c cs240=XXXX -v -p lab05where XXXX represents your lab section number (number only!).
| 2 points | Makefile exists and works correctly |
| 5 points | Read input correctly |
| 5 points | Recursive function is properly used |
| 5 points | Conversion works correctly |
| 3 points | Print the result correctly |