Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. Define an array to be cumulative if the nth (n > 0) element of the array is the sum of the first n elements

. Define an array to be cumulative if the nth (n > 0) element of the array is the sum of the first n elements of the array. So {1, 1, 2, 4, 8} is cumulative because

  1. a[1] == 1 == a[0]
  2. a[2] == 2 == a[0] + a[1]
  3. a[3] == 4 == a[0] + a[1] + a[2]
  4. a[4] == 8 == a[0] + a[1] + a[2] + a[4]

And {1, 1, 2, 5, 9} is not cumulative because a[3] == 5 != a[0] + a[1] + a[2]

Write a function named isCumulative that accepts an array of integers and returns 1 if the array is cumulative and 0 otherwise.

If you are programming in Java or C#, the function signature is int isCumulative(int[ ] a)

If you are programming in C or C++, the function signature is int isCumulative(int a[ ], int len) where len is the number of elements in the array

Some other examples:

if the input array is

isCumulative should return

{1}

0 (array must contain at least 2 elements)

{0,0,0,0,0,0}

1

{1, 1, 1, 1, 1, 1}

0

{3, 3, 6, 12, 24}

1

{-3, -3, -6, -12, -24}

1

{-3, -3, 6, 12, 24}

0

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_2

Step: 3

blur-text-image_3

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

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

More Books

Students also viewed these Databases questions

Question

3. Identify cultural universals in nonverbal communication.

Answered: 1 week ago