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

%3Cp%3EI%20need%20two%20separate%20pieces%20of%20code%20written%20that%20do%20th

ID: 3551458 • Letter: #

Question

%3Cp%3EI%20need%20two%20separate%20pieces%20of%20code%20written%20that%20do%20the%0Afollowing%3A%3C%2Fp%3E%0A%3Cp%3E%3Cbr%20%2F%3E%3C%2Fp%3E%0A%3Cp%3E%3Cbr%20%2F%3E%3C%2Fp%3E%0A%3Cp%3EFirst%20piece%3A%3C%2Fp%3E%0A%3Cp%3E%26gt%3B%26gt%3BAsk%20the%20user%20for%20an%20integer%2C%20m.%20Then%20use%20a%20for%20loop%20to%0Acreate%20a%20row%20array%20with%20m%20elements%3C%2Fp%3E%0A%3Cp%3Econsisting%20of%20all%20the%20integers%20from%201%20to%20m.%20Use%20disp%20to%20display%0Athe%20resulting%20array.%20For%20m%20use%2015.%3C%2Fp%3E%0A%3Cp%3E%3Cbr%20%2F%3E%3C%2Fp%3E%0A%3Cp%3ESecond%20piece%3A%3C%2Fp%3E%0A%3Cp%3E%26gt%3B%26gt%3BUse%20a%20for%20loop%20to%20extract%20every%20third%20element%20from%20the%0Aarray%20created%20in%20problem%203%20and%20store%20the%3C%2Fp%3E%0A%3Cp%3Eresults%20in%20a%20new%20array.%20Use%20disp%20to%20display%20the%20resulting%0Aarray.%3C%2Fp%3E%0A%3Cp%3E%3Cbr%20%2F%3E%3C%2Fp%3E%0A%3Cp%3ESince%20there%20are%20two%20pieces%2C%20I%20made%20it%20worth%20more%20points.%3C%2Fp%3E%0A

Explanation / Answer

write

1.

int i;

int x;

x = input(prompt);

a = zeroes(1,x);

for i:1:x

a[i] = i;

end

display(a');


2.

int c;

c=floor(x/3);

b = zeros(1,c);

for i=1:c

b[i] = a[3i];

end

display(b');


note: a' denotes tthe transform or it will make it a row instead of column.

and 'floor' function acts as a least integer function.