Docsity

Matlab Basic Programming - Fundamental Programming Concepts - Quiz, Exercises of Computer Programming

Toggle sidebar
bg1
Tick the correct output. Some questions have been marked as Multiple choice, the rest have one
correct answer.
1. i = 1;
while (i < 10)
i = i + 1
end
A. Numbers from 2 to 10
B. Numbers from 1 to 10
C. No output
D. Numbers from 1 to 11
2. Complete the for loop such that โ€˜helloโ€™ gets printed 10 times (Multiple choice)
for ____________
disp(โ€˜helloโ€™);
end
A. i = 1:5
B. i = 2:11
C. i = 1:10
D. i < 10
3. A = [1, 2, 3, 4, 5];
for i = 1 : length(A)
for j = 0 : 1
fprintf(โ€˜%d,โ€˜, A(i)^2 );
end
end
A. 1,2,3,4,5
B. 1,1,4,4,9,9,16,16,25,25
C. error
D. 1,4,9,16,25
4. function f = squareTest(N)
s = N * N;
end
squareTest(2)
A. Nothing will be printed
B. 2
C. 4
D. 4.00
5. function [x1, x2] = solveQuadratic(a, b, c)
%ax^2 + bx + c = 0
D = b * b โ€“ 4 * a * c;
x1 = (-b + sqrt(D)) / 2 / a;
x2 = (-b - sqrt(D)) / 2 / a;
end
docsity.com
pf2

Partial preview of the text

Download Matlab Basic Programming - Fundamental Programming Concepts - Quiz and more Exercises Computer Programming in PDF only on Docsity!

Tick the correct output. Some questions have been marked as Multiple choice, the rest have one correct answer.

  1. i = 1; while (i < 10) i = i + 1 end A. Numbers from 2 to 10 B. Numbers from 1 to 10 C. No output D. Numbers from 1 to 11
  2. Complete the for loop such that โ€˜helloโ€™ gets printed 10 times ( Multiple choice ) for ____________ disp(โ€˜helloโ€™); end A. i = 1:5 B. i = 2: C. i = 1:10 D. i < 10
  3. A = [1, 2, 3, 4, 5]; for i = 1 : length(A) for j = 0 : 1 fprintf(โ€˜%d,โ€˜, A(i)^2 ); end end A. 1 ,2,3,4,5 B. 1,1,4,4,9,9,16,16,25, C. error D. 1,4,9,16,
  4. function f = squareTest(N) s = N * N;

end

squareTest(2)

A. Nothing will be printed B. 2 C. 4 D. 4 .0 0

  1. function [x1, x2] = solveQuadratic(a, b, c) %ax^2 + bx + c = 0 D = b * b โ€“ 4 * a * c; x1 = (-b + sqrt(D)) / 2 / a; x2 = (-b - sqrt(D)) / 2 / a; end

docsity.com

QUIZ 2 Name:___________________________

netID:____________________________

[p,q] = solveQuadratic(1,2,1);

How many input and output arguments are there respectively? A. 2 and 3 B. 2 and 2 C. 3 and 2 D. 3 and 0

  1. A = 1; B = 0; ~((A & B) | (A | B)) A. 0 B. error C. 1 D. None

7. A = 2;

A = square(A); A = sqrt(A); disp(A); A. 2 B. 4 C. 1.4142 D. None

  1. A = 10; B = 9; disp(A == B) disp(B = A) A. 0 0

B. True True C. 0 10

D. 10

  1. Tick the code that would produce this output 1+2= A. 1 + 2 B. fprintf(โ€˜1+2=%dโ€™,1+2) C. 1 + 2; D. fprintf(โ€˜1+2โ€™)
  2. Tick the code that would produce this output ( Multiple Choice ) 1 2 3 4 A. for i = 1: fprintf(โ€˜%d โ€˜ , i); end

B. for i = 4: 7 fprintf(โ€˜%d โ€˜ , i- 3 ); end C. i = 1; while i <= 4 fprintf(โ€˜%d โ€˜ , i); i = i + 1; end

D. while i < 4 fprintf(โ€˜%d โ€˜ , i); end

docsity.com