What is the output of the following code? [code] for i=1:4 for j=1:4 a=5;a=a+5; end end[/code]

What is the output of the following code?
Code:
for i=1:4
for j=1:4
a=5;a=a+5;
end
end
A. No output will be shown
B. a=10;
C. a=80
D. Error in the code
 
Answer: b
Explanation: We have put a semi-colon after a=5. So, for both the “for loops” for i and j, we will keep assigning 5 to ‘a’ repeatedly. At last, we will do a=a+5. This will make ‘a’ as 10.
 

Tìm kiếm

Back
Top