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

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

int main()
{
    int n=0,i=0,j=0,k=0,sum=0,ii=0;

        int aa[128][128];
    for(ii=0;;ii++){
            //int bb[]={};
        cin >> n;
        if(n==0)break;
        //if(n==0 && x==0)break;
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                cin >> k;
                aa[i][j]=k;
                sum+=k;
            }
            aa[i][j]=sum;
            sum=0;
        }


        for(j=0;j<n+1;j++){
            for(i=0;i<n;i++){
                sum+=aa[i][j];
            }
        aa[i][j]=sum;
        sum=0;
        }
        for(i=0;i<n+1;i++){
            for(j=0;j<n+1;j++){
                if(aa[i][j]<10000)cout << ' ';
                if(aa[i][j]<1000)cout << ' ';
                if(aa[i][j]<100)cout << ' ';
                if(aa[i][j]<10)cout << ' ';
                cout << aa[i][j];
            }
            cout << endl;
        }
    }
    //cout << endl;


}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n;
	while(cin>>n,n){
		int a[11][11]={0};
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>a[i][j];
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;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++){
			for(int j=0;j<n;j++){
				a[n][n]+=a[i][j];
			}
		}
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				printf("%5d",a[i][j]);
			}
			cout<<endl;
		}
	}
}

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

int main(){
    while(true){
        int sheet[11][11] = {};
        int size; cin >> size;
        if(size == 0) return 0;
        
        // get
        for(int i=0; i<size; i++){
            int col_sum = 0;
            for(int j=0; j<size; j++){
                cin >> sheet[i][j];
                col_sum += sheet[i][j];
            }
            sheet[i][size] = col_sum;
        }
        
        // show
        for(int i=0; i<size; i++){
            for(int j=0; j<size+1; j++){
                cout << right << setw(5) << sheet[i][j];
            }
            cout << endl;
        }
        // row sum
        for(int i=0; i<size+1; i++){
            int row_sum = 0;
            for(int j=0; j<size; j++){
                row_sum += sheet[j][i];
            }
            cout << right << setw(5) << row_sum;
        }
        cout << endl;
    }
    return 0;
}