ABCs_iteration - end e b while loops Use the following...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function [A B] = ABCs_iteration(Z,N) % % DO NOT CHANGE THE FUNCTION HEADER (the first line of code) % % a) for loops. Fix the following for loop so that A is the vector Z in % reverse order. Replace every ? with the necessary code. You must utilize % the for loop to receive credit. % % If Z is [1 2 3 4 5], then A should look like this after each iteration: % [1] % [2 1] % [3 2 1] % [4 3 2 1] % [5 4 3 2 1] % A=[]; for ind=[1:length(Z)] % change this line A=[Z(ind) A]; % change this line
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: end e % b) while loops. Use the following while loop to count the number of % perfect squares between 1 and N inclusive. Store your answer in the % variable B. Replace every ? with the necessary code. You must utilize % this while loop to receive any credit. % num = 1; B = 0; while num<=N % change this line if mod(sqrt(num),1)==0 % change this line (it finds where the square % root of a number is an integer) B=B+1; end num = num+1; end...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern