Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		input := make([][]int, n+1, n+1)
		totalRow := make([]int, n+1, n+1)

		for i := 0; i < n; i++ {
			row := make([]int, n+1, n+1)
			scanner.Scan()

			row = numbers(scanner.Text())

			input[i] = row
			total(totalRow, row)
		}

		input[n] = totalRow

		for xk := range input {
			for yk, yv := range input[xk] {
				if yk == n {
					fmt.Printf("%5d\n", yv)
				} else {
					fmt.Printf("%5d", yv)
				}
			}
		}
	}
}

func total(sum, row []int) {
	for i := 0; i < len(row); i++ {
		sum[i] += row[i]
	}
}

func numbers(s string) []int {
	var n []int
	var sum int
	for _, f := range strings.Fields(s) {
		i, err := strconv.Atoi(f)
		if err == nil {
			n = append(n, i)
			sum += i
		}
	}
	n = append(n, sum)
	return n
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
#define MAX 11

int main(){
    int n,mat[MAX][MAX];
    
    while(true){
        for(int i = 0 ; i < MAX ; i++)
            for(int j = 0 ; j < MAX ; j++)
                mat[i][j] = 0;
        
        cin >> n;
        if(!n) break;
        
        for(int i = 0 ; i < n ; i++)
            for(int j = 0 ; j < n ; j++)
                cin >> mat[i][j];
        
        int sum = 0;
        for(int i = 0 ; i <= n ; i++){
            for(int j = 0 ; j <= n ; j++){
                sum += mat[i][j];
                if(j == n){
                    mat[i][j] = sum;
                    sum = 0;
                }
                
            }
        }
        
        for(int j = 0 ; j <= n ; j++){
            for(int i = 0 ; i <= n ; i++){
                sum += mat[i][j];
                if(i == n){
                    mat[i][j] = sum;
                    sum = 0;
                }
            }
        }
        
        int e = 0;
        for(int i = 0 ; i < n ; i++){
            e += mat[n][i];
            if(i == n-1) mat[n][n] = e;
        }
        
        for(int i = 0 ; i <= n ; i++){
            for(int j = 0 ; j <= n ; j++){
                if(!j) printf("%5d" ,mat[i][j]);
                else printf(" %5d" ,mat[i][j]);
            }
            cout << endl;
        }
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
void solve(){
  int table[200][200] = { 0 };

  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      scanf("%d", &table[i][j]);
      table[n][j] += table[i][j];
      table[i][n] += table[i][j];
    }
  }
  for (int i = 0; i < n; i++){
    table[n][n] += table[i][n];
  }
  for (int i = 0; i < n + 1; i++){
    int j = 0;
    printf("%5d", table[i][0]);
    for (j = 1; j < n + 1; j++){
      printf("%5d", table[i][j]);
    }
    printf("\n");
  }
}

int main(){
  while (scanf("%d", &n), n)solve();
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int t[100][100];
  int n;
  while( cin >> n,n ){
  int c_sum[100],sum[100];
  for(int i = 0 ; i <= n ; i++){
    c_sum[i] = 0;
    sum[i] = 0;
  }
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      cin >> t[j][i];
      sum[i] += t[j][i]; 
      c_sum[j] += t[j][i];
    }
  }
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      printf("%5d ",t[j][i]);
    }
    c_sum[n] += sum[i];
    printf("%5d\n",sum[i]);
  }
  for(int i = 0 ; i < n ; i++)printf("%5d ",c_sum[i]);
  printf("%5d\n",c_sum[n]);
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	while(cin >> n,n){
		int data[10+1][10+1];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}

		int all_sum = 0;

		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = 0; j < n; j++){
				sum += data[i][j];
			}
			data[i][n] = sum;
			all_sum += sum;
		}




		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = 0; j < n; j++){
				sum += data[j][i];
			}
			data[n][i] = sum;
		}
			data[n][n] = all_sum;


		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%5d", data[i][j]);
			}
			cout << endl;
		}
	}
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

	int N;
	while(cin>>N,N){
		vector<int> vi(N*N,0),vi2(N*2+1,0);
		for(int i=0;i<N;i++){
			int sum=0;
			for(int j=0;j<N;j++){
				int num;
				cin>>num;
				vi[i*N+j]=num;
				sum+=num;
			}
			vi2[i]=sum;
		}
		for(int i=0;i<N;i++){
			int sum=0;
			for(int j=0;j<N;j++){
				sum+=vi[i+j*N];
				printf("%5d",vi[i*N+j]);
			}
			printf("%5d\n",vi2[i]);
			vi2[N*2]+=vi2[i];
			vi2[N+i]=sum;
		}
		for(int i=0;i<=N;i++){
			printf("%5d",vi2[N+i]);
		}
		cout<<endl;
	}

	return 0;
}

C++: #include <iostream>
#include<iomanip>

using namespace std;

int main() {
    
    int n;
    while (cin >> n) {
    
    if(n == 0)
    break;
    
    int A[51][51] = {};
    
    for(int i=0;i<n;i++) { 
    for(int j=0;j<n;j++) {
    	
    	cin >> A[i][j];
    	
    	A[i][n] += A[i][j];
    	A[n][j] += A[i][j];
	}
	A[n][n] += A[i][n];
}

	for(int i=0;i<=n;i++) { 
    for(int j=0;j<n;j++) {
    	
    	cout << setw(4)<< A[i][j] << " ";
    }
	cout << setw(4)<< A[i][n];
	cout << "\n";
}
}
    return 0;
}

C++: #include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int  /*a=0,b=0,c=0,*/n=0,x=0,i=0,j=0,k=0,sum=0,ii=0;

        int aa[128][128];
        for(ii=0;;ii++){
            //int bb[]={};
            cin >> n;
            if(n==0)break;
            //if(n==0 && x==0)break;
            for(i=0;i<n;i++){
                for(j=0;j<n;j++){
                    cin >> k;
                    aa[i][j]=k;
                    sum+=k;
                }
                aa[i][j]=sum;
                sum=0;
            }


     for(j=0;j<n+1;j++){
            for(i=0;i<n;i++){
                sum+=aa[i][j];
            }
            aa[i][j]=sum;
            sum=0;

        }

            for(i=0;i<n+1;i++){
                for(j=0;j<n+1;j++){
                    cout << aa[i][j];
                    if(j<n)cout << ' ';
                }
                cout << endl;
            }

    }
        cout << endl;


}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.mc", "r", stdin);
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;
		if (n == 0){
			break;
		} // end if

		vector <vector <int> > sum (n+1, vector <int> (n+1, 0 ) );
		int i,j;

		for (i = 0; i < n; ++i){
			getline (cin, str );
			stringstream ss (str );
			for (j = 0; j < n; ++j){
				ss >> sum[i][j];
			} // end for
		} // end for

		for (i = 0; i < n; ++i){
			for (j = 0; j < n; ++j){
				sum[i][n] += sum[i][j];
			} // end for
		} // end for

		for (i = 0; i < n; ++i){
			for (j = 0; j < n; ++j){
				sum[n][j] += sum[i][j];
			} // end for
		} // end for
		for (i = 0; i < n; ++i){
			sum[n][n] += sum[i][n];
		} // end for

		for (i = 0; i <= n; ++i){
			for (j = 0; j <= n; ++j){
				cout << setw(5) << sum[i][j];
			} // end for
			cout << endl;
		} // end for
	} // end loop
		
	return 0;
}