± ± ± ± ± ± ± ± ± ± ±
- Imagine you need to subtract one number from another using MATLAB.
- You will not be using eval for this task.
- Given two ASCII strings representing two integers X and Y.
- Each of them has only 12 or less ASCII characters.
- Each of them represents signed integers, such as '+2345'
- Please output the result of (X-Y) in a similar style.
Solution Stats
Problem Comments
9 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers1541
Suggested Problems
-
Project Euler: Problem 3, Largest prime factor
1820 Solvers
-
Remove the two elements next to NaN value
712 Solvers
-
Flag largest magnitude swings as they occur
692 Solvers
-
446 Solvers
-
Flip the vector from right to left
11360 Solvers
More from this Author99
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
good
function z = mysub(x,y)
z = num2str( str2num(x) - str2num(y) );
end
why this is not working for this code?
Nice
Hi. My code only prints out '-' for a negative number but not '+' for a positive. Can anyone help? function Z = mysub(X,Y); W = (str2num(X))-(str2num(Y)); Z = num2str(W); end
actually each of them has 14 characters or less...15 if we count the signs.
Mark Sanderson, if W > 0 Z = ['+' ...]
how about solving this problem but not using any conversion functions like num2str , str2num , str2double ...
This problem needed much larger test cases. At least beyond intmax('uint64') range. Also negative inputs were not implemented at all.
hard