- 4

In a one- dimensional array consisting of n real elements, calculate: Product of elements located after the maximum element.

14th Apr 2022, 3:39 AM
Gulnur
1 Antwort
0
here is the process first create a copy of your original array, say newArr -- sort the newArr in ascending or descending choice is yours, i'm sorting it in ascending order because it is the default sorting -- now newArr is sorted in ascending order which means the largest number is at the last index, which means we know what is our largest number is -- now in the original array search for the largest number index. we got the largest number in the previous step. -- now we have found the index of largest number in the previous step. So from that ( index + 1) start a for loop and iterate through all the upcoming elements in the original array. With each iteration you need to multiply the elements. -- if you don't want to use for loop then you can slice or splice the array from that ( index+1) this will give you splicedArray. In this array you will have all the elements after the maximum elements. -- then you can use some mapping methods to get the product of all the elements in splicedArray.👍
14th Apr 2022, 4:19 AM
NonStop CODING
NonStop CODING - avatar