Write a program that asks the user to input a vector of integers of arbitrary length. Then, using a for-end loop the program examines each element of the vector. If the element is positive, its value is doubled. If the element is negative, its value is tripled. The program displays the vector that was entered and the modified vector. Execute the program, and when the program ask the user to input a vector type randi([−10 20], 1, 19). This creates a 19-element vector with random integers between −10 and 20.

Respuesta :

Answer:

%Program prompts user to input vector

v = input('Enter the input vector: ');

%Program shows the value that user entered

fprintf('The input vector:\n ')

disp(v)

%Loop for checking all array elements

for i = 1 : length(v)

   %check if the element is a positive number

   if v(i) > 0

       %double the element

       v(i) = v(i) * 2;

   %else the element is negative number.

   else

       %triple the element

       v(i) = v(i) * 3;

   end

end

%display the modified vector

fprintf('The modified vector:\n ')

disp(v)

ACCESS MORE