CS240 Lab 2
Number Conversion and Palindromic
To manipulate characters/numbers/strings, do base conversion and format output. It
introduces you to a new problem that may show you how computer scientists become
interested in questions for which answers may not be known. This leads to a search
for algorithms and answers that often lead to other questions. This is the research
Functions, global variables, for, while, if, local variables, getchar(), basic printf, one
and two-dimensional arrays, string manipulation (copy, compare, reverse,
concatenate) and output-formatting using a two-dimensional array.
Task 0: Download the Initial Source Files
Download the file
and untar it by typing the command.
tar -xvf lab2-src.tar
contains the initial sources as well as the script testall that will
test all your programs. To build your programs type "make" inside the directory lab2-
src. Make sure you compile and test your programs in lore.cs.purdue.edu.
Task 1: Number conversions
Write a program to convert a given number from one base to another. The format is:
convert <basefrom> <baseto> <number>
You now know how to input arguments on the command line. Assume that basefrom
and baseto are integers between 2 and 25 (both inclusive). Since base 16 uses the
characters A, B, C, D, E, F to represent decimal numbers 10 through 15, bases 17
through 20 will involve additional characters. For example, base 20 will involve the
additional characters G, H, I and J. Use defensive programming to make sure your
command line arguments are what you would expect. You may assume that no
number (in any base) has more than 32 digits, and all numbers are nonnegative.