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>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
  int n;
  while(true){
    cin >> n;
    if(n==0)
      break;

    vector<vector<int> > mop;
    vector<int> mup; 
    mup.resize(n+1);
    for(int i=0; i<n; i++){
      vector<int> mip;
      int k, l=0;
      for(int j=0; j<n; j++){
	cin >> k;
	mip.push_back(k);
	l+=k;
	mup[j]+=k;
      }
      mip.push_back(l);
      mop.push_back(mip);
    }
    for(int i=0; i<n; i++){
      mup[n]+=mup[i];
      for(int j=0; j<n+1; j++){
	printf("%5d", mop[i][j]);
      }
      cout << endl;
    }
    for(int i=0; i<=n; i++)
      printf("%5d", mup[i]);
    cout << endl;
  }

  return 0;
}

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

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

    for(i = 0; i <= n; i++){
      for(j = 0; j <= n; j++){
	std::cout << std::right << std::setw(5) << array[i][j];
      }
      cout << endl;
    } 

  }

    
    
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  int M[12][12];
  while(cin>>n,n){
    rep(i,n)rep(j,n)cin>>M[i][j];
    rep(i,n){
      int tmp=0;
      rep(j,n)tmp+=M[i][j];
      M[i][n]=tmp;
    }
    rep(i,n){
      int tmp=0;
      rep(j,n)tmp+=M[j][i];
      M[n][i]=tmp;
    }
    int tmp=0;
    rep(i,n)tmp+=M[n][i];
    M[n][n]=tmp;
    rep(i,n+1){
      rep(j,n+1){
        if(M[i][j]<100){
          cout<<"   "<<M[i][j];
        }else if(M[i][j]<1000){
          cout<<"  "<<M[i][j];
        }else if(M[i][j]<10000){
          cout<<' '<<M[i][j];
        }else{
          cout<<M[i][j];
        }
      }
      cout<<endl;
    }
  }
  return 0;
}

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

int Matrix[11][11];

int main(void){
  int n;
  while(cin >> n && n != 0){
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> Matrix[i][j];
    int s = 0;
    for(int i = 0; i < n; i++){
      int sumt = 0, sumy = 0;
      for(int j = 0; j < n; j++){
        sumt += Matrix[i][j];
        sumy += Matrix[j][i];
      }
      Matrix[i][n] = sumt;
      Matrix[n][i] = sumy;
      s += sumt + sumy;
    }
    Matrix[n][n] = s;
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
        printf("%5d", Matrix[j][i]);
      }
      cout << endl;
    }
  }
  return 0;
}

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