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>

using namespace std;

int main(void){
    while(true) {
        int n;
        cin >> n;
        if (n == 0) break;
        int cell[n+1][n+1];
        int sum_r, sum_c;
        for (int i = 0; i < n; i++) {
            sum_r = 0;
            for (int j = 0; j < n; j++) {
                cin >> cell[i][j];
                sum_r += cell[i][j];
            }
            cell[i][n] = sum_r;
        }
        for (int i = 0; i <= n; i++) {
            sum_c = 0;
            for (int j = 0; j < n; j++) {
                sum_c += cell[j][i];
            }
            cell[n][i] = sum_c;
        }
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                cout << cell[i][j];
                if (j < n) cout << " ";
            }
            cout << endl;
        }
    }
    return 0;
}

C++: #include <stdio.h>

int main(void){
	int matrix[10][10],i,j,dataset;
	scanf("%d",&dataset);
	while(dataset!=0){

		//init add total norm
		for(i=0;i<dataset+1;i++){
			matrix[dataset][i]=0;
			matrix[i][dataset]=0;
		}

		//input and calc
		for(i=0;i<dataset;i++){
			for(j=0;j<dataset;j++){
				scanf("%d",&matrix[i][j]);
				matrix[i][dataset]+=matrix[i][j];
			}
		}

		//calc
		for(j=0;j<dataset+1;j++){
			for(i=0;i<dataset;i++){
				matrix[dataset][j]+=matrix[i][j];
			}
		}

		//output
                for(i=0;i<dataset+1;i++){
                        for(j=0;j<dataset+1;j++){
                                printf("%5d",matrix[i][j]);
                        }
			printf("\n");
                }
	scanf("%d",&dataset);
	}
}

C++: #include <stdio.h>
#include <stdlib.h>
int main(){
	int n,i,j;
	while(1){
		int matrix[11][11]={0};
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&matrix[i][j]);
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				matrix[n][j] += matrix[i][j];
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<=n;j++){
				matrix[j][n] += matrix[j][i];
			}
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d ",matrix[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[i][j]);
            if(i == number || (j == number && i == number))
                cout << endl;
            else
                cout << " ";
            
        }
    }
    return 0;
    
  
}

C++: #include <iostream>
using namespace std;
int main(void)
{
	int n;
	while(cin>>n){
		int date[11][11]={0};
		if(!n) break;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				cin >> date[i][j];
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0; j<n; j++){
				date[i][n] += date[i][j];
			}
		}
		for(int i=0;i<=n;i++){
			for(int j=0; j<n; j++){
				date[n][i] += date[j][i];
			}
		}
		for(int i=0; i<=n; i++){
			for(int j=0; j<=n; j++){
				printf("%5d",date[i][j]);;
				if(j!=n) cout << " ";
			}
			cout << "\n";
		}
	}
	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(6)<<ober[i][j]<<" ";
                A+=ober[i][j];
            }
            cout<<setw(6)<<A<<"\n";
            lon+=A;
            A=0;
        }
        for(int i=0;i<n;i++)cout<<setw(6)<<side[i]<<" ";
        cout<<setw(6)<<lon<<"\n";
        lon=0;
    }
}

C++: #include <stdio.h>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long Int;

int main() {
    for (;;) {
        int n;
        scanf("%d", &n);
        if (n == 0) return 0;
        vector<vector<int> > a(n+1, vector<int>(n+1, 0));
        rep (i, n) rep (j, n) scanf("%d", &a[i][j]);
        rep (i, n) rep (j, n) a[n][i] += a[j][i];
        rep (i, n+1) rep (j, n) a[i][n] += a[i][j];
        rep (i, n+1) rep (j, n+1) printf("%5d%c", a[i][j], "\n "[j<n]);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
int main()
{
	while (1) {
		int sum = 0;
		int num;
		std::cin >> num;
		if (num == 0)break;
		std::vector<std::vector<int>>vec(num + 1, std::vector<int>(num + 1));
		for (int i = 0; i < num; ++i) {
			for (int j = 0; j < num; ++j) {
				std::cin >> vec[i][j];
			}
		}
		for (int i = 0; i < num; ++i) {
			for (int j = 0; j < num; ++j) {
				vec[num][i] += vec[j][i];
				sum += vec[j][i];
				vec[i][num] += vec[i][j];
			}
		}
		vec[num][num] = sum;
		for (int i = 0; i < num + 1; ++i) {
			for (int j = 0; j < num + 1; ++j) {
				if (j == num)std::cout << vec[i][j] << std::endl;
				else std::cout << vec[i][j] << " ";
			}
		}
	}
	return 0;
}

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

int main() {
	const int MAX_N = 10;
	int N;
	int table[MAX_N][MAX_N];
	int keta[MAX_N][MAX_N];
	int max_keta;
	int sum[MAX_N], retu;
	int res;

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

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

	return 0;
}