Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write this program using Python Your assignment is to write a program that has a function to find the largest element in an array. You

Write this program using Python

Your assignment is to write a program that has a function to find the largest element in an array. You may write your program in the Python program where the data structure is a list instead of an array.

Below you will find attached starter code in Python. You can use this code as a starting point for your program.

You must use the following in your program:

Global variables (the five arrays/lists)

Arrays, or in Python Lists, (the five arrays/lists)

A function that you define (findMax)

A function parameter (the array/list you pass to the function)

A local variable (currentMax in the function findMax)

A loop (the main part of the function findMax)

A conditional (the test to see if there is a new currentMax value)

A function return value (currentMax is returned at the end of findMax)

Output (putting the maximum values on the screen.

image text in transcribed

Program To Find the maximum integer in an array of positive integers var array1 [2,12,4,10, 6,81 var array2 [1,3,15,5, 7,9,11,13] var array [8] var array4 [20, 18, 16, 14,12,10,8,6]; var array5 [2,4,6,8,10,12,14] *declare function findMax which takes an array as its only parameter and returns the maximum integer in that array Algorithm: Set a local variable currentMax to the first element in the array Write a for loop from 0 to the length of the array For each element in the array: test to see if the list element at the index of the loop counter is greater than currentMax if it is, then set currentMax to the value of that array element. After the loop ends, have the function return currentMax. Set fill to black so text shows up on the screen Call findMax five times, once for each of the arrays above Print the result of each function call to the screen

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago