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>
using namespace std;
int main(){
  int n;
  int i,j;
  while(1){
    cin >> n;
    if(n==0)break;
    int data[11][11]={0};
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	cin >> data[i][j];
	data[i][n]+=data[i][j];
	data[n][j]+=data[i][j];
	data[n][n]+=data[i][j];
      }
     }
    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	cout.width(5);
	//	cout.fill(' ');
	cout << data[i][j];
      }
      cout << endl;
    }
  }
}

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

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}
		vector<int> col_sum(n + 1);
		for (int i = 0;i != n + 1;++i) {
			col_sum[i] = 0;
		}
		for (int i = 0;i != n;++i) {
			int row_sum = 0;
			for (int j = 0;j != n;++j) {
				int num;
				cin >> num;
				cout << " " << num;
				col_sum[j] += num;
				row_sum += num;
			}
			cout << " " << row_sum << endl;
			col_sum[n] += row_sum;
		}
		for (int i = 0;i != n + 1;++i) {
			cout << " " << col_sum[i];
		}
		cout << endl;
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n;
  while(cin>>n, n){
    int allsum = 0;
    vector<int> v(n);
    REP(i, n){
      int sum = 0;
      REP(j, n){
        int tmp;
        cin >> tmp;
        printf("%5d",tmp);
        allsum += tmp; sum += tmp;
        v[j] += tmp;
      }
      printf("%5d\n",sum);
    }
    REP(i, n)
      printf("%5d",v[i]);
    printf("%5d\n",allsum);
  }
  return 0;
}

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

int main(){
	int n,i,j;
	while(cin >> n && n){
		int table[11][11] = {{0}};
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				cin >> table[i][j];
				table[i][n] += table[i][j];
				table[n][j] += table[i][j];
			}
			table[n][n] += table[i][n];
		}
		for(i = 0;i <= n;i++){
			for(j = 0;j <= n;j++){
				printf("%5d",table[i][j]);
			}
			cout << "\n";
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int dp[15][15];
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>dp[i][j];
	int x=0;
	for(int i=0;i<n;i++){
		int h=0;
		for(int j=0;j<n;j++)
			h+=dp[i][j];
		dp[i][n]=h;
		x+=h;
	}
	for(int i=0;i<n;i++){
		int h=0;
		for(int j=0;j<n;j++)
			h+=dp[j][i];
		dp[n][i]=h;
	}
	dp[n][n]=x;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			int k=1,h=10;
			while(true){
				if(dp[i][j]<h)
					break;
				h*=10;
				k++;
			}
			for(int l=0;l<5-k;l++)
				cout<<" ";
			cout<<dp[i][j];
		}
		cout<<endl;
	}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=10000;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
const int MAX=100001;
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
ll keta(ll n){
    int d=0;
    while(n>0){
        n/=10;
        d++;
    }
    return d;
}
int main(){
    int n;
    while(cin>>n,n){
        int a[12][12]={};
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cin>>a[i][j];
                a[i][n]+=a[i][j];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                a[n][i]+=a[j][i];
            }
        }
        for(int i=0;i<n;i++){
            a[n][n]+=a[n][i];
        }
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                for(int k=keta(a[i][j]);k<5;k++){
                    cout<<" ";
                }
                cout<<a[i][j];
            }
            if(i==n)break;
            cout<<endl;
        }
    }
	return 0;
}

C++: #include<stdio.h>
#include<memory.h>
int main(){
	int n;
	int i,j,a[110][110]={0};
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				scanf("%d",&a[i][j]);
				a[i][n+1]+=a[i][j];
				a[n+1][j]+=a[i][j];
			}
		}
		for(j=1;j<=n;j++){
			a[n+1][n+1]+=a[n+1][j];
		}
		for(i=1;i<=n+1;i++){
			for(j=1;j<=n+1;j++){
				if(j==n+1) printf("%5d",a[i][j]);
				else printf("%5d ",a[i][j]);
			}
			printf("\n");
		}
		memset(a,0,sizeof(a));
	}
	return 0;
}

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

int main() {
	int n;

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

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

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

	return 0;
}

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

int main() {
	int n;

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

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

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

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main() {
	int n,i,j,d,m[11][11];
	while(cin >> n) {
		if (n==0) break;
		memset(m,0,sizeof(m));
		for (i=0;i<n;i++) for (j=0;j<n;j++) {
			cin >> d;
			m[i][j]=d; m[i][n]+=d; m[n][j]+=d; m[n][n]+=d;
		}
		for (i=0;i<=n;i++) {
			for (j=0;j<=n;j++) printf("%5d",m[i][j]);
			printf("\n");
		}
	}
	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);
	}
}