I have done this so far, i donot know where my mistake is or where i m going wrong, I have come up with this program 1st time. We have to ask from the user amount of elements in an array which i have done using dynamic array. Then we have to pass 2 arguments one is the size of an array and the other is array(float type).
The function should replace the contents of each cell with the sum of the contents of all the cells in the original array from the left end to the cell in question. for example if i have array {1,2,3,4,5} function should return {1,3,6,10,15}. This is my program below please tell me what changes I have to make in my existing code.
#include <iostream>
using namespace std;
float compute(int x, float arr[]){
float sum=0;
for(int i=0; i<x;i++){
sum+=arr[i];
arr[i]=sum;
}
return arr;
}
int main(){
int x;
cout<<"How many elements you want"<<endl;
cin>>x;
float *p=new float[x];
for(int i=0; i<x; i++){
cin>>p[i];
}
cout<<compute(x,p);
return 0;
}
float compute(int x, float arr[])returns ?std::vector<float>instad.std::partial_sum