What is the output of the following code? [code]function c = addem(ap,q) p=nargn-1 switch p case 2 c = ap*q; case 1

Trung Minh

New member
What is the output of the following code?
Code:
function c = addem(ap,q)
p=nargn-1
switch p
    case 2
        c = ap*q;
    case 1
        c = sin(q)
    otherwise
        c = 0;
end
addem(1,2,3,4,5,6,7,8)
A. 2
B. Error due to too many inputs
C. 28
D. Error due to nargn
 
Answer: d
Explanation: The first error MATLAB invokes is the fact that too many values are given as input. So it returns that as input. The next error would be that the nargin keyword is misspelled as nargn. But MATLAB returns the first error only.
 

Tìm kiếm

Back
Top