Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I'm in need of help with this program. It's in C++ and deals with pointers and dynamic arrays. Problem : Given an unsorted array

Hi, I'm in need of help with this program. It's in C++ and deals with pointers and dynamic arrays.

Problem: Given an unsorted array A of size N of non-negative integers, find a continuous sub-array which adds to the given number. Declare dynamic arrays and use only pointers syntax (no [ ]s or (ptr+i) stuff. To delete a dynamic array, delete[] ptr.

Input will be the number of input values to enter followed by the sum to compare with. Print out the continuous sub-array of values that are equal to sum or the message No sum found. There may be more than one sub-array to be found in a given input so print out all continuous sums.

Example:

Input: 6 10 First number represents 6 values to enter and 10 is the sum.

3 5 8 2 3 5 6 input values for the array.

Output: 8 2 and 2 3 5 these are continuous sub-array/slice of array values that sum to 10

Your input data sets: I called it nums.txt

6 10

3 5 8 2 3 5

8 20

5 10 3 3 10 3 4 14

11 19

8 5 3 3 7 6 5 1 7 2 4

9 15

3 8 4 3 10 2 3 8 2

6 12

8 5 3 3 4 5

30 20

10 12 8 5 15 5 10 8 2 4 6 9 1 7 6 3 2 7 2 18 20 5 2 2 7 9 2 3 15 5

30 19

4 2 4 3 6 2 1 5 3 2 4 7 1 3 4 1 3 3 1 5 2 1 5 1 4 2 2 2 3 5

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

Entity Alignment Concepts Recent Advances And Novel Approaches

Authors: Xiang Zhao ,Weixin Zeng ,Jiuyang Tang

1st Edition

9819942527, 978-9819942527

Students also viewed these Databases questions

Question

What do you think of the MBO program developed by Drucker?

Answered: 1 week ago