Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. (50 pt) In this problem you will perform various tasks on a 1-by-n array V, whose elements are integers from 1 to 9. In

image text in transcribed

3. (50 pt) In this problem you will perform various tasks on a 1-by-n array V, whose elements are integers from 1 to 9. In the template, you are already given the matrix V to be V = [1, 4, 3, 3, 5, 6, 7, 1, 2,9, 8, 6, 6, 3, 1,4,9,5); For each of the following tasks test your code for many different values and lengths of V (the graders may change the V matrix when grading to evaluate whether your code is correct). (a) Write code using a while loop to calculate the sum of all elements in the vector V. Define the calculated sum as variable V1. For example, for V = [1, 2, 3, 4, 5, 6], V1 = 21. (Note: you will get zero point for this question if you use the sum function or use a for loop). (b) Write code to flip the sign of each odd number in the original matrix V. Define the new vector as V2. For example, V = [1, 2, 3, 4, 5, 6] would become V2 = (-1, 2, -3, 4, -5, 6]. (c) Write code to find the number of times (defined as V3) that two successive elements in V are the same. For example, for V = [1, 2, 2, 4, 6, 6), V3 = 2. (d) (Bonus Question, 10 pt) Write code using a for loop that will show all the elements of the V in a reverse order. Define the new vector as V4. For example, V = [1, 2, 3, 4, 5, 6] would become V4 = [6, 5, 4, 3, 2, 1). (Note: you will get zero point for this question if you use the flip function directly)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago