What will be the output of the following code? [code]close all; for x = 1.5 : .5 : 2; y=3; x=y+3 clc end[/code]

What will be the output of the following code?
Code:
close all;
for x = 1.5 : .5 : 2;
y=3; 
x=y+3
 clc
end
A. No value will be stored
B. The result will be printed
C. The result will be printed twice but no value will remain in the Workspace
D. The loop will not run
 
Answer: c
Explanation: The loop will run twice and the final value of y is 5 while that of x is 2. Each time the loop runs, no result shall be printed since the ‘ ; ‘ at the end of the last line suppresses the result and it gets stored in MATLAB.
Output: x = 4.5
x = 5
 

Tìm kiếm

Back
Top