What is the output of the following code? [code]for i=1:5 for j=1:6 a(i,j)=input(); end end[/code]

What is the output of the following code?
Code:
for i=1:5
for j=1:6
a(i,j)=input();
end
end
A. No output
B. Error
C. Asks user to input a 5*6 matrix
D. Asks and displays a 5*6 matrix
 
Answer: b
Explanation: The syntax for input is wrong. There should be a pair of single inverted commas within the syntax, even though we don’t have to write anything necessarily within them. But to take any input, we have to use the
syntax: a(i,j)=input(‘’) OR a(i,j)=input(‘Enter value coloumn-wise:’)
We can choose to place a semi-colon at the end, then the matrix won’t be displayed after every input.
 

Tìm kiếm

Back
Top