2
Answers

Split an array like below dynamically.

Pruthvi Patel

Pruthvi Patel

8y
321
1
arr[]={1,2,3,4,5,6,6,7,6,5,4,3,7,8,8,8,4,3,2,8,6,5,3,4....n}
split=2
sum=2
then the result array should be like this.
res[0]=47 //1+2+5+6+6+5+7+8+4+3
res[1]=53 //3+4+6+7+4+3+8+8+2+8
Please help me to do this.
 
if
split=3
sum=2 then
 res[0]= 41   //1+2+6+7+7+8+2+8
 res[2]= 45  //3+4+6+5+8+8+6+5
 res[3]= 32 //5+6+4+3+4+3+3+4 
 
res[] should be vary with split if split is 4 then res[4] should be also there.this should be  dynamically
value of sum and split is vary between 1 to n. 
please help me to do this.
Thanks 

Answers (2)