Suppose you need to store the integer 5857458488 on some \"primive\" computer bu
ID: 3733008 • Letter: S
Question
Suppose you need to store the integer 5857458488 on some "primive" computer but that computer cannot store any numbers larger than 100. And you need to do some arithmetic calculations with this ten digit number on that computer. You could store each digit of 5857458488 in ten individual files and identify which file corresponds to each digit but thern arithmetic calculations with 5857458488 may be intricate to program. Noting that 2*3*5*7*11 * 13*17*19*23*29 6469693230 > 5857458488, use the Chinese Remainder Theorem to design an intelligent means to store 5857458488 that wl enable calculations with the ten digit number. Be sure to explicitly state how 5857458488 is stored. Use your design to calculate and store the outcome of the difference 857458488-4927100893Explanation / Answer
Solution:
We will be using array data structure to solve this problem what we will do is we will save each digits in the array index and also make sure while saving that the digits are saved in order of LSB to MSB from 0th index to nth index.
This was the LSB will be at 0th index so we can simply do 10^index and multiply with the number in the array and add all of them to get the actual value of the numbers.
so,
the logic will be
while(number>0)
{
array[i]= number%10; //i wil start from 0
number= number/10;
i++; ///This will make sure that the index value of the array increases as we are saving each digit one by one
}
so 5857458488 will be stored as
This is how the number will be stored and for subtraction with
we will subtract each digit from the 0th index of the array and save it in the thrid array if if there is a bit which needs to be borrowed it can be done from immediate next array cell.
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
8 8 4 8 5 4 7 5 8 5Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.