Base Converter Problem: In this assignment you will create a Base Converter whic
ID: 3565842 • Letter: B
Question
Base Converter
Problem:
In this assignment you will create a Base Converter which takes 3 integer
parameters: a number, its base, and the new base that you want to convert it to.
Your converter returns the converted number as a string.
You will be provided with an input file. The first line has a single integer n which
indicates the number of conversions required. This is followed by n strings one per
line in ascending order (strings will not be longer than length 10). These represent
the results that your code should produce for the conversions.
The rest of the input file is n lines, each with 3 integer inputs, for the base converter.
Requirements:
You are required to include the following functions in your code. Functions
2-4 should be recursive
1. buildAnsArray : a function which reads the n answers from the input file
into an array of strings, maintaining the ascending order in which they
appeared in the file. Your function should return a pointer to the array of
answers.
2. baseConversion: takes three integer parameters and returns a string
representing the answer of the base conversion. For example when
baseConversion (6,10,2) is called, it will take 6 in base 10, convert it to
base 2 and return the string
Explanation / Answer
#include void main(void) { char base_digits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; int converted_number[64]; long int number_to_convert; int next_digit, base, index=0; /* get the number and base */ printf("Enter number and desired base: "); scanf("%ld %i", &number_to_convert, &base); /* convert to the indicated base */ while (number_to_convert != 0) { converted_number[index] = number_to_convert % base; number_to_convert = number_to_convert / base; ++index; } /* now print the result in reverse order */ --index; /* back up to last entry in the array */ printf(" Converted Number = "); for( ; index>=0; index--) /* go backward through array */ { printf("%c", base_digits[converted_number[index]]); } printf(" "); }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.