1. Please dont ask people to post the code for you (in this forum at least). First show what you have tried and others will help you to fix any problems in it.
2. If you want to write separate functions for each summation, it is very easy with nested loop. If you want a single function that can do any of the above, you need to create a coeff array with 0 or 1 depending on whether you want to add a column entry or not. For example, col1 = col1+col2 will have coeff array (1,1,0,0), col1=col1+col3+col4 will have coeff array (1,0,1,1). Then, all you need to do is create a function that takes in the array col, the array coeff and the col number of result c, run a loop through all rows and nest in loop through all columns setting in each row col[c]= sum of coeffxcol... col1=coeff1xcol1+coeff2xcol2+coeff3xcol3+coeff4xcol4.
Hope that helps...
Arun