What will be the output of the following code? [code]for i = 1 : 1 p=i-1 i=i+1; clc end [/code]

Thê Hy

New member
What will be the output of the following code?
Code:
for i = 1 : 1
p=i-1
i=i+1;
clc
end
A. i=2
B. p will be printed
C. Error
D. Cannot be determined
 
Answer: a
Explanation: The value of i won’t be printed since we have ended it with a semi-colon. The value of p will get printed and then the clc command will remove it from the command window. Instead, the value of I will be stored in the workspace as 2.
 

Tìm kiếm

Back
Top