The idea here is to in a way create our own “Very big integer type” by using integer arrays.solved


Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment


5/5 - (1 vote)

The idea here is to in a way create our own “Very big integer type” by using integer arrays.
Right now the largest “short int” is 32,767 and the largest “long int” is 2,147,483,647, where the
last has only ten digits. But what if we wanted an integer that had 20 digits or even more. We
could use int arrays and create our own data type by letting each digit in our number be stored in
each array element. We could actually create an integer that has more than 1,000 digits in it.
The way it works is to store each “Large int” in an integer array, so if the user enters the number
“7834” and we have an int array named N, then N[0] has 7, N[1] has 8, N[2] has 3 and N[3] has
the number 4 in it. So depending on the array size would determine the number of digits our
“Large int” could be.
This lab deals with having the user enter any positive large integer, lets use a maximum number
of digits to be 20, hence this will be our array size. This number will then have to be stored in an
int array, but each separate digit of the number must be stored separately in the correct array
element location. To extract one digit at a time one needs to read each digit first as a single
character, convert this character to an integer and store this integer into the correct array
location. Then read the next character digit and so on until the newline is encountered.
When program is done reading in and storing number, then display the array on the screen.
Sample output is shown:
Program will continue to read and display numbers until user decides to quit.
Please enter large number — 984567
Large twenty digit Number is
Continue ‘Y’ or ‘N’, response —
**Hint: To convert the character digit to an integer you need to subtract the ASCII number 48
from the character. i.e. ASCII for character zero is 48, ‘0’ = 48, so 48 – 48 is integer 0.