Go: package main

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

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

		a := make([][]int, n+1)
		for i := 0; i < n; i++ {
			sum := 0
			stdin.Scan()
			a[i] = make([]int, n+1)
			str := strings.Split(stdin.Text(), " ")
			for j := 0; j < n; j++ {
				a[i][j], _ = strconv.Atoi(str[j])
				sum += a[i][j]
				fmt.Printf("%5d", a[i][j])
			}
			a[i][n] = sum
			fmt.Printf("%5d\n", a[i][n])
		}
		a[n] = make([]int, n+1)
		for i := 0; i <= n; i++ {
			sum := 0
			for j := 0; j < n; j++ {
				sum += a[j][i]
			}
			a[n][i] = sum
			fmt.Printf("%5d", a[n][i])
		}
		fmt.Println()
	}
}

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);
	}
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	int pt[11][11];
	int sum=0;
	while (true){
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> pt[i][j];
				sum += pt[i][j];
			}
			pt[i][n] = sum;
			sum = 0;
		}
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n; j++){
				sum += pt[j][i];
			}
			pt[n][i] = sum;
			sum = 0;
		}
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n + 1; j++){
				if (j == n)cout << pt[i][j];
				else
				cout << pt[i][j] << ' ';
			}
			cout << endl;
		}
	}
	return 0;
}