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 <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int n;
  while (cin >> n, n){
    int table[n][n], x[n], y[n], sum = 0;
    REP(i, n){
      REP(j, n) cin >> table[i][j];
      x[i] = y[i] = 0;
    }
    REP(i, n){
      cout << setw(4) << right << table[i][0];
      x[i] = table[i][0];
      FOR(j, 1, n){
        cout << setw(4) << right << table[i][j];
        x[i] += table[i][j];
      }
      cout << setw(4) << right << x[i] << endl;
    }
    REP(i, n){
      REP(j, n) y[i] += table[j][i];
    }
    cout << setw(4) << right << y[0];
    FOR(i, 1, n) cout << setw(4) << right << y[i];
    REP(i, n) sum += x[i];
    cout << setw(4) << right << sum << endl;
  }
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<vector<int>>dates(N + 1, vector<int>(N + 1));
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cin >> dates[i][j];
				dates[N][j] += dates[i][j];
				dates[i][N] += dates[i][j];
				dates[N][N] += dates[i][j];
			}
		}
		for (int i = 0; i <= N; ++i) {
			for (int j = 0; j <= N; ++j) {
				printf("%5d", dates[i][j]);
			}
			printf("\n");
		}
	}
	
	return 0;
}

C++: #include<stdio.h>
int main()
{
	int masu[12][12];
	int n,i,j,w=0,h=0,t=0;
	
	for(;;h=0,w=0,t=0){
		for(i=0;i<11;i++){
			for(j=0;j<11;j++){
				masu[i][j]=0;
			}
		}
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&masu[i][j]);
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				w+=masu[i][j];
				h+=masu[j][i];
			}
			masu[i][j]=w;
			masu[j][i]=h;
			w=0;
			h=0;
		}
		
		for(i=0;i<=n;i++){
			t+=masu[n][i];
		}
		masu[i-1][j]=t;
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d",masu[i][j]);
			}
			puts("");
		}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;

int a[11][11];

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

    for (i = 0; i < n; i++){
      for (j = 0; j < n; j++){
        cin >> a[i][j];
      }
    }

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

    for (i = 0; i <= n; i++){
      cout << a[i][0];
      for (j = 1; j <= n; j++){
        cout << " " << a[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

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

int map[12][12];

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

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

C++: #include <cstdio>

int matrix[12][12];
int n;

int main() {
  while(scanf("%d", &n), n) {
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
	scanf("%d", &matrix[i][j]);
      }
    }

    // output
    for (int i=0; i<n; i++) {
      int sum = 0;
      for (int j=0; j<n; j++) {
	sum += matrix[i][j];
	printf("%5d", matrix[i][j]);
      }
      matrix[i][n] = sum; 
      printf("%5d\n", sum);
    }

    for (int j=0; j<=n; j++) {
      int sum = 0;
      for (int k=0; k<n; k++) {
	sum += matrix[k][j];
      }
      printf("%5d", sum);
    }
    printf("\n");
  }
}

C++: #include <cstdio>

int main(){
  int n;
  
  while(1){
    scanf("%d", &n);
    if(!n) break;
    
    int table[11][11] = {0};
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	scanf("%d", &table[i][j]);
      }
    }
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	table[i][n] += table[i][j];
	table[n][i] += table[j][i];
      }
    }
    
    for(int i=0; i<n; i++)
      table[n][n] += table[n][i];
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++)
	printf("%5d", table[i][j]);
      putchar('\n');
    }
  }
    
  return 0;
}

C++: #include <cstdio>

int main(void)
{
    int data[11][11];
    int n;
    
    while (1){
        scanf("%d", &n);
        if (n == 0) break;
        
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                data[i][j] = 0;
            }
        }
        
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                scanf("%d", &data[i][j]);
                data[i][n] += data[i][j];
                data[n][j] += data[i][j];
                data[n][n] += data[i][j];
            }
        }
        
        for (int i = 0; i <= n; i++){
            for (int j = 0; j <= n; j++){
                printf("%5d", data[i][j]);
            }
            printf("\n");
        }
        
    }
    
    return (0);
}