Pruthvi Patel

Pruthvi Patel

  • NA
  • 129
  • 21.7k

Split an Array Like below

Oct 6 2016 6:16 AM
This is different than previous uploaded question please see carefully.
I have one array called ans[i].
ans[i]={1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16} //n no.of inputed element.Not fix array
and i want to split in group of 3 and stored it in array.
 
Like this if x=2 the it should store the summation of 1+4+7+10+13..like below.
res[0]= 35 //1+4+7+10+13
res[1]=40 //2+5+8+11+14
res[2]=45 //3+6+9+12+15
 
if x=3 then,
res[0]=1+5+9+13
res[1]=2+6+10+14
res[2]=3+7+11+15
res[3]=4+8+12+16 
 
if x=1 then
 res[0]=1+3+5+7+9+11+13+15 
 res[2]=2+4+6+8+10+12+14+16
 
if x=4,5... for n no of input for n size of an array.
please give code for this. 

Answers (4)