- Related Questions & Answers
- Array sum after dividing numbers from previous?
- Maximum sum after repeatedly dividing N by a divisor in C++
- Maximize array sum after K negation in C++
- Prime numbers after prime P with sum S in C++
- Sum of Even Numbers After Queries in Python
- Dividing an array – JavaScript
- Minimum sum of two numbers formed from digits of an array in C++
- Count number of digits after decimal on dividing a number in C++
- Maximum subarray sum in an array created after repeated concatenation in C++
- Sum triangle from an array in C programming
- Consecutive Numbers Sum in C++
- Maximize Sum Of Array After K Negations in Python
- Maximum array sum that can be obtained after exactly k changes in C++
- Sum of Square Numbers in C++
- Count of Smaller Numbers After Self in C++

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Array is a sequence of elements of same data type. in this problem we are going to consider integer array for solving the problem. in this problem we are going to find sum of Elements found by dividing the element from the element proceeding it.

Let’s take a few examples to understand this Problem better −

Array : 3 , 5 ,98, 345 Sum : 26

**Explanation** − 3 + 5/3 + 98/5 + 345/98 = 3 + 1 + 19 + 3 = 26

We have divided each element with its preceding element and considered only integer parts of the divisions to find the sum.

Array : 2, 5 , 8, 11, 43 , 78 , 234 Sum : 13

**Explanation** − 2 + 2 + 1 + 1 + 3 + 1 + 3 = 13

this Algorithm traverse each element of the array. and divide it by the element preceding it. Then, adds the quotient value to sum variable.

Input : Array - int arr[] Output : int sum

Step 1: Initialize sum = arr[0] Step 2: for(i = 1 to size of arr ) follow step 3 Step 3 : sum = sum + (arr[i]/arr[i-0] ) Step 4: print the sum

This is an easy four step algorithm to find *the sum of array after dividing numbers from previous numbers*. We have initialised the sum by the first element of the array because according to the logic the first element does not have any elements which means it cannot be divided by any element. so taking under consideration for loop create an error because we will be accessing the element at -1 index which is wrong.

#include<stdio.h> int main() { int arr[] = { 2, 5 , 8, 11, 43 , 78 , 234 }; int n = sizeof(arr)/sizeof(arr[0]); int sum = arr[0]; for (int i = 1; i < n; i++) { sum += arr[i] / arr[i - 1]; } printf("The sum of array after dividing number from previous numbers is %d \n", sum); return 0; }

The sum of array after dividing number from previous number is 13.

Advertisements