CSC 303: DIGITAL LOGIC AND COMPUTER DESIGN
CSC 219 (Programming in C)
Lab Exercise 2
This lab provides more C input and output practice.
Write a program called lab2.c. Your lab2.c program should “convert” an integer into another base. But note that the conversion is only to OUTPUT the read in integer in a different base, not hold it internally.
The input integer could be in decimal, octal or hexadecimal. The output could be converted into any of the bases. A sample run is below. The user’s response is in boldface.
Base of input integer: Enter d for decimal, h for hexadecimal or o for octal: d
Enter the number: 178
Enter the base of the output (d, h or o): h
The integer 178 in decimal is b2 in hexadecimal
Do you wish to do another? (Y or N): Y
Base of input integer: Enter d for decimal, h for hexadecimal or o for octal: o
Enter the number: 423
Enter the base of the output: d
The integer 423 in octal is 275 in decimal
Do you wish to do another? (Y or N): N
Print your .c file and the sample output and submit
HINT: This program is simpler than some of you may think it to be. Recall how the embedded conversion strings are used in C printf() and scanf() calls as discussed in class.