Reference no: EM13685
Write C program that will input two values from the user (with a prompt !?) that are a Value and a Base with which you will evaluate and output the Value in the given Base.
The Base (B) will be anything from 1 to 16. Values could be non-negative.
Have a main() method and a sub-method (?) called DivAlg() whose prototype is
void DivAlg(int, int);
or
void DivAlg(int Val, int Base);
A typical call might be DivAlg(-1, 16). The suggestion is that Value is first argument, Base is second.
For your own survival you probably should check input for valid values (non-negative Value, Base in range).
Demonstrate fabulosity by choosing fine reprsentative data including some error conditions.
Recall the actual algorithm ** which simply produces digits IN REVERSE ORDER and thus, you will need to have some intermediate character buffer into which to put ascii characters corresponding to the digit values product.
Use a 'table lookup' to map numeric values to ascii characters. By this I mean that you will declare an array char TABLE[16] ={'0', '1', ... , '9', 'A', 'B' ... }; // for asciification ! You're welcome. and then you can map some digit D by simple array referece a la TABLE[D]
Code should be well documented because a human will read it. Documentation should include:
Initial Description of assignment including who, what when , how etc when due, how to use
Use prototypes for any methods other than main.
For any method provide documentation of input , output , and algorithm.
Any possibly interesting segments of code should be narrated.
For all methods, declare all variables before any executable code. Thus for (int i = ... ) ought not , and cannot be used.