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

#define int long long

signed main() {
    int n;
    while(cin>>n, n!=0) {
        int G[n+1][n+1] = {0};
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                cin >> G[i][j];
                G[i][n]+=G[i][j];
                G[n][j]+=G[i][j];
                G[n][n]+=G[i][j];
            }
        }
        for(int i=0; i<n+1; ++i) {
            for(int j=0; j<n+1; ++j) {
                cout << setw(5) << G[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int board[15][15];
signed main() {
    int n;
    while(cin >> n, n) {
        memset(board, 0, sizeof(board));
        rep(i,0,n) rep(j,0,n) cin >> board[i][j];
        rep(i,0,n) rep(j,0,n) {
            board[i][n] += board[i][j];
            board[n][n] += board[i][j];
        }
        rep(j,0,n) rep(i,0,n) {
            board[n][j] += board[i][j];
        }
        repq(i,0,n) {
            repq(j,0,n) printf("%5lld", board[i][j]);
            cout << endl;
        }
    }
    return 0;
}

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

int main() {
	int N;

	while (cin >> N && N != 0) {
		int dataset[11][11] = {0};
        for (int i = 0; i != N; ++i) {
            for (int j = 0; j != N; ++j) {
                cin >> dataset[i][j];
            }
        }

        for (int i = 0; i != N; ++i) {
            for (int j = 0; j != N; ++j) {
                dataset[i][N] += dataset[i][j];
            }
        }

        for (int i = 0; i <= N; ++i) {
            for (int j = 0; j != N; ++j) {
                dataset[N][i] += dataset[j][i];
            }
        }

        for (int i = 0; i != N+1; ++i) {
            for (int j = 0; j != N+1; ++j) {
                cout << setw(5) << dataset[i][j];
            } 
            cout << endl;
        }
	}
    return 0;
}

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++){
				cout << pt[i][j] << ' ';
			}
			cout << endl;
		}
	}
	return 0;
}

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

int hoge(int w);
int getKetasu(int n);

int main(){
	int w;
	
	while(1){
	 cin>>w;
	 if(w==0){break;}
	 hoge(w);
	}
	
	return 0;
}

int hoge(int w){	//?????£???????????????
	int t[10][10];
	int x,y,i;
	
	for(y=0;y<w;y++){
	 for(x=0;x<w;x++){
	  cin>>t[x][y];
	 }
	}
	
	for(y=0;y<w;y++){
	 t[w][y]=0;
	 for(x=0;x<w;x++){
	  t[w][y]+=t[x][y];
	 }
	}
	for(x=0;x<=w;x++){
	 t[x][w]=0;
	 for(y=0;y<w;y++){
	  t[x][w]+=t[x][y];
	 }
	}
	
	for(y=0;y<=w;y++){
	 for(x=0;x<=w;x++){
	  for(i=getKetasu(t[x][y]);i<5;i++){cout<<" ";}
	  cout<<t[x][y];
	 }
	 cout<<endl;
	}
	
	return 0;
}

int getKetasu(int n){	//?????°?????????
	if(n<10){
	 return 1;
	}else if(n<100){
	 return 2;
	}else if(n<1000){
	 return 3;
	}else{
	 return 4;
	}
}

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

using namespace std;

int main() {

	int i, j, n, m[11][11];

	while(cin >> n) {
		if(n==0)
			break;
		for(i=0; i<n+1; i++) {
			for(j=0; j<n+1; j++) {
				m[i][j]=0;
			}
		}
		for(i=0; i<n; i++) {
			for(j=0; j<n; j++) {
				cin >> m[i][j];
				m[i][n]+=m[i][j];
				m[n][j]+=m[i][j];
				m[n][n]+=m[i][j];
			}
		}
		for(i=0; i<n+1; i++) {
			for(j=0; j<n+1; j++) {
				printf("%5d", m[i][j]);
				if(j==n)
				 cout << endl;
			}
		}

	}

	return 0;

}

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

int main() {
	int n;
	while (1) {
		cin >> n;
		if (n == 0)break;
		int matrix[11][11];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> matrix[i][j];
			}
		}
		int num1, num2;
		for (int i = 0; i < n; i++) {
			num1 = 0; num2 = 0;
			for (int j = 0; j < n; j++) {
				num1 += matrix[i][j];
				num2 += matrix[j][i];
			}
			matrix[i][n] = num1;
			matrix[n][i] = num2;
		}
		num1 = 0;
		for (int i = 0; i < n; i++) {
			num1 += matrix[n][i];
		}
		matrix[n][n] = num1;
		for (int i = 0; i < n + 1; i++) {
			for (int j = 0; j < n + 1; j++) {
				printf("%5d", matrix[i][j]);
			}
			printf("\n");
		}
	}
}

C++: #include <stdio.h>

int main(void)
{
	int a[11][11] = {0};
	int n, i, j;

	while (1)
	{
		scanf("%d", &n);

		if (n != 0)
		{
			for (i = 0; i < n; i++)
				for (j = 0; j < n; j++)
					scanf("%d", &a[i][j]);

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

			for (j = 0; j < n; j++)
				for (i = 0; i < n; i++)
					a[n][j] += a[i][j];

			for (i = 0; i <= n; i++)
				for (j = 0; j <= n; j++)
				{
					printf("%5d", a[i][j]);
					if (j == n)
						printf("\n");
					else
						printf(" ");
				}
		}
		else
			break;
	}

	return 0;
}