2
Answers

Split and sum array like below

Pruthvi Patel

Pruthvi Patel

7y
393
1
arr[]={1,3,2,4,6,7,8,9,10, 11,12,16,5,8,7,8,4,6};
split=2; // the arr[] will be divide in 2(no of splits) parts each with equal elements  split=1,2,3...n
skip=2; // skip is no of element to be skipped. skip=1,2,3...n
size of res[] should be accordingly.
then
res[0]=15 //1+4+8
res[1]=18//3+6+9
res[2]=19 //2+7+10
res[3]=24 //11+5+8
res[4]= 24 //12+8+4
res[5]= 29//16+7+6 
and like wise split can be 1 to n.
arr[]={1,2,3...n} elements
This should be dynamically.
Please help me to do this.
Thanks

Answers (2)