### i need a little help for my assignment

i need help on the algorithm to write this program. please don't give me the code to solve the entire problem i just need the algorithm for the summation part.this is the question;

i want a an algorithm to sum elements in an array such that if we have A={a1,a2,a3,...,an}. we will create another array like B={a1+a2,a3+a4,...,a(n-1),an}

thank you.

this is my code so far, i need help urgently.
#include<iostream>
using namespace std;

int main()
{
int Arr[100],n,i,sum=0;

cout<<"Enter number of elements you want to insert ";
cin>>n;

for(i=0;i<n;i++)
{

cout<<"Enter element "<<i+1<<":";
cin>>Arr[i];
}

for(i=0;i<n;i++)
sum+=Arr[i];

cout<<"\nThe sum of Array is :"<<sum;

return 0;
}
 B={a1+a2,a3+a4,...,a(n-1),an}

 B={a1+a2,a3+a4,...,a(n-1)+an}

Anyway, it seems there is a condition, n must be an even number, if we want to add them in pairs. (Or maybe we can work around that if necessary).

It seems you need to go through the array in steps of 2:
 `` `` `` for (i=0; i

Then it is easy enough to take consecutive elements from the first array. Store the result in the second array at subscript `i/2`.
actually the 1,2,3,n-1,n are subscripts of a
Topic archived. No new replies allowed.