Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume that there is a vector of N integers; i.e, a matrix of size N rows, 1 col

ID: 3630439 • Letter: A

Question

Assume that there is a vector of N integers; i.e, a matrix of size N rows, 1 column. Write a "while" loop that prints each integer and its square, but after encountering the integer 7 and printing its square, the loop terminates.

For example, if a= [11 9 8 7 2 5 4]

11^2=121
9^2=81
8^2=64
7^2=49

Hint 1: Although this task can be accomplished with a C-style "do/until" loop, no such construct exists in MatLab.

Hint2: Consider the case where 7 is NOT in the array. Ensure that this case is handled.

Need to use the program MatLab to solve this question.

Explanation / Answer

for x=1:N a(x) 'square' a(x)^2 if (a(x)==7) break; end end this is how to solve it basically, its tested and works (a is the array N is the number elements of the array, if u wish dont know the number of items in the array you can use the size function (if you need help with that function let me know) there is a small problem, i dont know of a way to print strings in matlab, so when typing 'square' it prints out ans=square and then prints the square of the number, but the rest are tested and working, if you need more help before rating me let me know