Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function s = nsum(a,b)
- %MatLab have a function called sum
- s = str2num(cell2mat(a))+str2num(cell2mat(b));
- end
- function s = sub(a,b)
- s = str2num(cell2mat(a))-str2num(cell2mat(b));
- end
- function m = multi(a,b)
- m = str2num(cell2mat(a))*str2num(cell2mat(b));
- end
- function d = div(a,b)
- d = str2num(cell2mat(a))/str2num(cell2mat(b));
- end
- calc = input('Insert some values and the type of calculation (Ex: 53+35): ','s');
- not_digit = isstrprop(calc,'digit');
- for e = 1:1:length(calc)
- if not_digit(1,e) == 0
- numbers = strsplit(calc, calc(1,e));
- result = 0;
- switch calc(1,e)
- case '+'
- result = nsum(numbers(1,1),numbers(1,2));
- case '-'
- result = sub(numbers(1,1),numbers(1,2));
- case '*'
- result = multi(numbers(1,1),numbers(1,2));
- case '/'
- result = div(numbers(1,1),numbers(1,2));
- end
- fprintf('The result of %s = %d\n',calc,result)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement