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>

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		int nums[11][11];
		for (int i = 0; i < n; ++i)
			for (int j = 0; j < n; ++j)
				cin >> nums[i][j];

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

		nums[n][n] = 0;
		for (int i = 0; i < n; ++i)
			nums[n][n] += nums[i][n];

		for (int i = 0; i <= n; ++i, cout << endl)
			for (int j = 0; j <= n; ++j)
				printf("%5d", nums[i][j]);
	}
}

C++: #include <iostream>
using namespace std;
int main()
{
	int n, num[11][11];
	while (1) {
		if (cin >> n, !n) break;
		for (int i=0; i<11; i++) for (int j=0; j<11; j++) num[i][j] = 0;
		for (int i=0; i<n; i++)  for (int j=0; j<n; j++) cin >> num[i][j];
		for (int i=0; i<10; i++) for (int j=0; j<10; j++) num[10][i] += num[j][i];
		for (int i=0; i<11; i++)
			for (int j=0; j<10; j++) num[i][10] += num[i][j];

		for (int i=0; i<11; i++) {
			for (int j=0; j<11; j++) {if ((i<n && j<n) || (i==10 && j<n) || (j==10 && i<n) || (j==10 && i==10)) {cout.width(5); cout << num[i][j];}}
			if ((i < n) || (i == 10))  cout << endl;
		}
	}

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

int main(){
	int n;
	while(1){
		cin>>n;
		int dt[n+1][n+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>dt[i][j];
			}
		}
		for(int x=0;x<n+1;x++){
			dt[x][n]=0;
		}
		for(int y=0;y<n;y++){
			dt[n][y]=0;
		}
		for(int k=0;k<n;k++){
			for(int l=0;l<n;l++){
				dt[k][n]+=dt[k][l];
			}
		}
		for(int x=0;x<=n;x++){
			for(int y=0;y<n;y++){
				dt[n][x]+=dt[y][x];
			}
		}
		for(int a=0;a<=n;a++){
			for(int b=0;b<=n;b++){
				if(dt[a][b]/10==0)cout<<"    "<<dt[a][b];
				else if(dt[a][b]/100==0)cout<<"   "<<dt[a][b];
				else if(dt[a][b]/1000==0)cout<<"  "<<dt[a][b];
			}
			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];
        }
        cout<<endl;
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                printf("%5d",a[i][j]);
            }
            if(i==n)break;
            cout<<endl;
        }
    }
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define int long long
signed main(){
        int a;
        while( scanf("%lld", &a) != EOF ){
                if(a==0) break;
                vector<vector<int>> m(a+1,vector<int>(a+1,0));
                for(int i=0;i<a;i++){
                        int s = 0;
                        for(int j=0;j<a;j++){
                                int b;
                                scanf("%lld", &b);
                                m[i][j] = b;
                                s += b;
                        }
                        m[i][a] = s;
                }
                for(int j=0;j<a+1;j++){
                        int s = 0;
                        for(int i=0;i<a;i++){
                                s += m[i][j];
                        }
                        m[a][j] = s;
                }
                for(int i=0;i<a+1;i++){
                        for(int j=0;j<a+1;j++){
                                printf("%5lld", m[i][j]);
                        }
                        printf("\n");
                }
        }
        return 0;
}

C++: 
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long lon
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)

using namespace std;

int main (void){
    
    int number;
    while(cin >> number,number)
    {
        int math[11][11] ={0};
        REP(i,number)
        {
            REP(j,number)
            cin >> math[i][j];
        }
        REP(i,number)
            REP(j,number)
        math[i][number] += math[i][j];
        REP(i,number)
            REP(j,number)
        math[number][i] += math[j][i];
        REP(i,number)
        REP(j,number)
        math[number][number]+= math[i][j];
        REP(j, number+1)
        REP(i,number+1){
            printf("%5d",math[j][i]);
            if(i == number || (j == number && i == number))
                cout << endl;
            else
                cout << " ";
            
        }
    }
    return 0;
    
  
}

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

int main(){
	int n;

	while(cin >> n, n){
		vector<int> vsum(n);
		int hsum = 0;
		int k;
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = 0; j < n; j++){
				cin >> k;
				printf("%5d", k);
				sum+=k;
				vsum[j]+=k;
			}
			printf("%5d\n", sum);
			hsum += sum;
		}
		vsum.push_back(hsum);

		for(int i = 0; i < n+1; i++){
			printf("%5d", vsum[i]);
		}
		cout << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,sum,hoge,piyo;
    sum=0;
    hoge=0;
    piyo=0;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            std::vector<vector<int>> vec(n+1,vector<int>(n+1));
            for (int i=0;i<n;i++) {
                for (int j=0;j<n;j++) {
                    cin>>a;
                    printf("%5d",a);
                    vec[i][j]=a;
                    sum=sum+a;
                    if (j==n-1) {
                        printf("%5d",sum);
                        cout<<endl;
                        sum=0;
                    }
                }
            }
            for (int k=0;k<n;k++) {
                for (int l=0;l<n;l++) {
                    hoge=hoge+vec[l][k];
                }
                printf("%5d",hoge);
                piyo=piyo+hoge;
                hoge=0;
            }
            printf("%5d",piyo);
            cout<<endl;
            piyo=0;
        }
    }
}