Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

13.28 Pointers - Ex4 General Description You are given an array that may contain both positive and negative integers. Your goal is to find the

13.28 Pointers - Ex4

General Description

You are given an array that may contain both positive and negative integers. Your goal is to find the sum of any contiguous subarray of numbers which has the largest sum.

For example, if the given array is {6, -2, 1, 3, 4, 6, -2, -6, -4, -7}, then the maximum subarray sum is 18 (see highlighted elements).

Tasks

Read an integer from the user that represents how many elements you will allocate in memory as an array. You can store this in a variable called N.

Create an array of N elements.

Then you will read N integers from the user given to you in the following format and store them in the array:

 

Write a function call findBest that receives the array, the size of the array and returns the maximum subarray sum.

Print out the return value from your function using the format "%d". Do this by calling your function in the main function.

Example 1:

When the input is:

10 6 -2 1 3 4 6 -2 -6 -4 -7 

The output is:

18

Example 2:

When the input is:

9

-2 6 6 -2 7 -3 -6 -3 -8?

The output is:

17

 

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 Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago