What does the code below do?   clear vec = randi(20,1,100)-10; iter=0; k=1; while k<= length(vec)     if vec(k)<0       vec(k)= vec(k) * -1;     end    k = k+1; end

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter16: Searching, Sorting And Vector Type
Section: Chapter Questions
Problem 24SA
icon
Related questions
Question

What does the code below do?

 

clear
vec = randi(20,1,100)-10;
iter=0;
k=1;
while k<= length(vec)
    if vec(k)<0
      vec(k)= vec(k) * -1;
    end
   k = k+1;
end
a.

This code generates a vector with 20 random integer elements between 1 and 100, and changes the sign of all negative elements.

b.

This code generates a vector with 20 random integer elements between -100 and 100, and replaces all the negative integers with a positive integer of the same absolute value.

c.

This code generates a vector with 100 random integer elements between -10 and 10, and changes the sign of all negative elements.

d.

This code generates a vector with 100 random integer elements between 20 and 100, and changes the sign of the elements coverting all poivitive ones to negative and all negative ones to positive.

e.

This code generates a vector with 20 random integer elements between 1 and 100, and changes the sign of all the elements.

 
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning