Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write function called huge_add that adds together two positive integers of any l

ID: 3847154 • Letter: W

Question

Write function called huge_add that adds together two positive integers of any length specified as char
vectors using decimal notation. The single output argument is the result and it is a char vector as well. The
inputs and output must contain digits only; no commas, spaces or any other characters are allowed. If any of
these assumptions are violated by the input, the function returns the number -1. Hint: you cannot use any of
the built-in numerical data types of MATLAB to do the calculation since the function needs to work for
numbers that are larger than what can be represented as a number in MATLAB.

Explanation / Answer

function n=chrToNum(vec)
n=0
j=0
n=str2num(vec)
end


function sum=huge_add(num1,num2)
n1=chrToNum(num1)
n2=chrToNum(num2)

sum=n1+n2

sum=num2str(sum)

fprintf(" %d",sum)
end

num1='123456789'
num2='987654321'
huge_add(num1,num2)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote