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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

ll n, table[100][100];

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

C++: #include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int n[127], tn=0,ni=0,all = 0, i = 0;
	int data[1024][10];
	int tdata[10] = { 0 };
	
	//input
	while (1){
		cin >> n[ni];
		if (n[ni] == 0)break;
		tn += n[ni];

		for (; i < tn; i++){
			for (int j = 0; j < n[ni]; j++){
				cin >> data[i][j];
			}
		}
		ni++;
	}


	//output
	for (int k = 0; k < ni; k++){
		for (int i = 0; i < n[k]; i++, all = 0){
			for (int j = 0; j < n[k]; j++){
				printf("%5d", data[i][j]);
				all += data[i][j];
				tdata[j] += data[i][j];
			}
			printf("%5d\n", all);
		}

		all = 0;
		for (int i = 0; i < n[k]; i++){
			printf("%5d", tdata[i]);
			all += tdata[i];
		}
		printf("%5d\n", all);

		for (int i = 0; i < n[k]; i++){
			tdata[i] = 0;
		}
		all = 0;
	}
	return 0;
}

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

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

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++)
{
if(num[i][j]==0)a==4;
else if(num[i][j]>0)	a =5-( (int)log10((double)(num[i][j]) )+ 1);
else if(num[i][j]<0)	a =4-( (int)log10((double)(-num[i][j]) )+ 1);
for(int k=0;k<a;k++)
{cout<<" ";}
cout<<num[i][j];}
cout<<endl;


}

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


}

return 0;
}

C++: 4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0

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

using namespace std;

int main()
{
    int n;
    while (cin >> n && n != 0) {
        vector<int> row(n);
        vector<vector<int>> sheet(n);

        sheet.clear();
        for (auto i = 0; i < n; i++) {
            row.clear();
            for (auto j = 0; j < n; j++) {
                int in;
                cin >> in;
                row.push_back(in);
            }
            sheet.push_back(row);
        }

        vector<int> zero(n + 1, 0);
        sheet.resize(n + 1, zero);
        for (auto i = 0; i < n; i++) {
            sheet.at(i).resize(n + 1, 0);
            for (auto j = 0; j < n; j++) {
                sheet.at(n).at(i) += sheet.at(j).at(i);
                sheet.at(i).at(n) += sheet.at(i).at(j);
                sheet.at(n).at(n) += sheet.at(i).at(j);
            }
        }

        for (auto i = 0; i < n + 1; i++) {
            for (auto j = 0; j < n + 1; j++) {
                cout << setw(5) << sheet.at(i).at(j);
            }
            cout << endl;
        }
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    for (;;) {
    int n;
    cin >> n;
    if (n == 0) return 0;

    int matrix[n+1][n+1];

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

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

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

    matrix[n][n] = 0;
    for (int i = 0; i < n; i++) {
        matrix[n][n] += matrix[n][i];
    }
    
    for (int i = 0; i < n+1; i++) {
        for (int j = 0; j < n+1; j++) {
            cout.width(5);
            if (j == n) 
                cout << matrix[i][j];
            else 
                cout << matrix[i][j];
        }
        cout << endl;
    }
    }

    return 0;
}

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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) break;
    int v[n + 1][n + 1];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> v[i][j];
      }
    }
    // x
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = 0; j < n; j++) {
        sum += v[i][j];
      }
      v[i][n] = sum;
    }
    // y
    for (int j = 0; j < n; j++) {
      int sum = 0;
      for (int i = 0; i < n; i++) {
        sum += v[i][j];
      }
      v[n][j] = sum;
    }
    int k = 0;
    for (int i = 0; i < n; i++) {
      k += v[n][i];
    }
    v[n][n] = k;

    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        if (j == n) {
          cout << setw(5) << v[i][j] << endl;
        } else {
          cout << setw(5) << v[i][j] << " ";
        }
      }
    }

  }
}

C++: #include <iostream>

using namespace std;
int main(){
    int n;
    int matr[11][11];
    while(cin >> n,n){
        matr[n][n]=0;
        for(int i=0;i<n;i++){
            matr[i][n]=0;
            for(int j=0;j<n;j++){
                if(i==0)matr[n][j]=0;
                cin >> matr[i][j];
                matr[i][n]+=matr[i][j];
                matr[n][j]+=matr[i][j];
                matr[n][n]+=matr[i][j];
            }
        }
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                printf("%5d",matr[i][j]);
            }
            printf("\n");
        }
    }
    return 0;
}

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

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

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++)
{
if(num[i][j]==0)a==4;
else if(num[i][j]>0)	a =5-( (int)log10((double)(num[i][j]) )+ 1);
else if(num[i][j]<0)	a =4-( (int)log10((double)(num[i][j]) )+ 1);
for(int k=0;k<a;k++)
{cout<<" ";}
cout<<num[i][j];}
cout<<endl;


}

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


}

return 0;
}