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>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int s[n+1][n+1];
    for(int i=0;i<n;i++){
      int a = 0;
      for(int j=0;j<n;j++){
	cin >> s[i][j];
	a += s[i][j];
      }
      s[i][n] = a;
    }
    for(int i=0;i<n;i++){
      int a = 0;
      for(int j=0;j<n;j++){
	a += s[j][i];
      }
      s[n][i] = a;
    }
    int a = 0;
    for(int i=0;i<n;i++) a += s[n][i]; 
    s[n][n] = a;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	if(s[i][j]>=10000) cout << s[i][j];
	else if(s[i][j]>=1000) cout << " " << s[i][j];
	else if(s[i][j]>=100) cout << "  " << s[i][j];
	else if(s[i][j]>=10) cout << "   " << s[i][j];
	else if(s[i][j]>=0) cout << "    " << s[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

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

void calculate(int const n);
void show_table(const vector<int> table, const int n);

int main()
{
	int n = 0;

	while(true) {
		cin >> n;
		if(n==0) break;
		calculate(n);
	}

	return 0;
}

void calculate(int const n)
{
	int row_n = n+1;
	vector<int> table((row_n)*(row_n),0);

	// 表への入力
	for(int i=1;i<=row_n*n;i++) {
		if(i%row_n==0) ;			//  結果が入るところはスキップ
		else
			cin >> table[i-1];
	}
	cout << "ok1\n";

	// 右側の和の計算 
	for(int i=n;i<=(row_n)*(row_n);i+=(row_n))
		for(int j=1;j<=n;j++)
			table[i] += table[i-j];

	// 下側の和の計算
	int count = 0;
	int j = 0;
	for(int i=0;i<n;i++) {
		count = 0;
		j = i;
		while(true) {
			table[(row_n)*n+i] += table[j];
			j += (row_n);
			count++;
			if(count==n) break;
		}
	}
	// 右下の和の計算
	for(int i=n;i<(row_n)*n;i+=(row_n))
		table[(row_n)*(row_n)-1] += table[i];

	show_table(table,n);
}

void show_table(const vector<int> table,const int n)
{
	int row_n = n+1;
	for(int i=0;i<(row_n)*(row_n);i+=(row_n)) {
		for(int j=i;j<i+row_n;j++)
			cout << setw(5) << table[j];
		cout << endl;
	}
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	int n, a[10][10] = {}, sum_h[11] = {}, sum_v[11] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			cout << a[i][j] << " ";
			sum_h[i] += a[i][j];
			sum_v[j] += a[i][j];
		}
		sum_v[n] += sum_h[i];
		cout << sum_h[i] << endl;
	}
	for (int i = 0; i < n; i++)
		cout << sum_v[i] << " ";
	cout << sum_v[n] << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    
    while (true) {
        cin >> n;
        if (!n) {
            break;
        }
        vector<vector<int> > v(n + 1, vector<int>(n + 1, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[i][n] += v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[n][i] += v[j][i];
            }
            v[n][n] += v[n][i];
        }
        for (int i = 0; i < n + 1; i++) {
            for (int j = 0; j < n + 1; j++) {
                cout << setw(5) << v[i][j] << ' ';
            }
            cout << '\n';
        }
    }
}

C++: #include<stdio.h>

int a[1000][1000],i,j,n;

int main(){
    scanf("%d",&n);
    while(n!=0){
        a[n][n]=0;
        for(i=0;i<n;i++){
            a[i][n]=0;
            a[n][i]=0;
            for(j=0;j<n;j++){
                scanf("%d",&a[i][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+1;i++){
            for(j=0;j<n+1;j++){
                printf("% 5d",a[i][j]);
            }
            printf("\n");
        }
    }
    
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int s[n+1][n+1];
    for(int i=0;i<n;i++){
      int a = 0;
      for(int j=0;j<n;j++){
	cin >> s[i][j];
	a += s[i][j];
      }
      s[i][n] = a;
    }
    for(int i=0;i<n;i++){
      int a = 0;
      for(int j=0;j<n;j++){
	a += s[j][i];
      }
      s[n][i] = a;
    }
    int a = 0;
    for(int i=0;i<n;i++) a += s[n][i]; 
    s[n][n] = a;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	if(s[i][j]>=10000) cout << s[i][j] << endl;
	else if(s[i][j]>=1000) cout << " " << s[i][j];
	else if(s[i][j]>=100) cout << "  " << s[i][j];
	else if(s[i][j]>=10) cout << "   " << s[i][j];
	else if(s[i][j]>=0) cout << "    " << s[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
	int ta[100][100],sum[100];
	int n,all;
	while(cin>>n,n){
	all=0;
	for(int i=0;i<100;i++)sum[i]=0,fill(ta[i],ta[i]+100,0);
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>ta[i][j];
	for(int i=0;i<n;i++){
		int tnow=0;
		for(int j=0;j<n;j++){
		cout<<ta[i][j];
		string ss=itos(ta[i][j]);
		for(int i=0;i<5-ss.size();i++)cout<<" ";
		sum[j]+=ta[i][j];
		tnow+=ta[i][j];
		all+=ta[i][j];
		}
		cout<<tnow<<endl;
	}
	for(int i=0;i<n;i++){cout<<sum[i];string ss=itos(sum[i]);for(int i=0;i<5-ss.size();i++)cout<<" ";}
	cout<<all<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<iomanip>
using namespace std;
int main(void)
{
    int n,A=0,ober[10][10],side[10],lon=0;
    while(1){
        for(int i=0;i<12;i++)side[i]=0;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cin>>ober[i][j];
                side[j]+=ober[i][j];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<setw(5)<<ober[i][j]<<" ";
                A+=ober[i][j];
            }
            cout<<setw(5)<<A<<"\n";
            lon+=A;
            A=0;
        }
        for(int i=0;i<n;i++)cout<<setw(5)<<side[i]<<" ";
        cout<<setw(5)<<lon<<"\n";
        lon=0;
    }
}

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

int main() {
	const int MAX_N = 20;
	int N;
	int table[MAX_N][MAX_N];

	while (1) {
		for (int i = 0;i < MAX_N;i++) {
			for (int j = 0;j < MAX_N;j++) {
				table[i][j] = 0;
			}
		}
		cin >> N;
		if (!N)break;
		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++) {
			for (int j = 0;j < N;j++) {
				table[i][N] += table[i][j];
				table[N][j] += table[i][j];
				table[N][N] += table[i][j];
			}
		}

		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				for (int k = 0;k < 5-(log10(table[i][j])+1);k++) {
					cout << " ";
				}
				cout << table[i][j];
			}
			cout << endl;
		}
	}

	return 0;
}