lab2 - CS240 Lab 2 Number Conversion and Palindromic...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS240 Lab 2 Number Conversion and Palindromic Numbers Project Goal: 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 process. Topics covered: 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 lab2-src.tar and untar it by typing the command. tar -xvf lab2-src.tar The directory lab2-src 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 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.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
To convert a number, say (123)9, from base 9 to another base such as base 8, simply convert from base 9 to decimal (i.e., base 10), to get the number, i.e., (1 x 9 2 ) + (2 x 9
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/18/2012 for the course CS 240 taught by Professor Rego during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 5

lab2 - CS240 Lab 2 Number Conversion and Palindromic...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online