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 <stdio.h>
#include <math.h>
using namespace std;

/*
int log10(int n) {
	int keta = 0;
	do{
		n /= 10;
		keta++;
	} while (n > 0);
	return keta;
}
*/

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;
			}
		}
		scanf("%d", &N);
		if (!N)break;
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				scanf("%d", &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-((table[i][j]==0)? 1 : log10(table[i][j]) + 1);k++) {
					printf(" ");
				}
				printf("%d", table[i][j]);
			}
			printf("\n");
		}
	}

	return 0;
}

C++: #include<iostream>
int main() {
	int n;
	while (std::cin >> n){
		if (n == 0)break;
		int l[11][11];
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++)
				std::cin >> l[i][j];
			l[i][n] = 0;
			for (int j = 0; j < n; j++)
				l[i][n] += l[i][j];
		}
		for (int i = 0; i < n + 1; i++){
			l[n][i] = 0;
			for (int j = 0; j < n; j++){
				l[n][i] += l[j][i];
			}
		}
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n + 1; j++){
				std::cout.width(5);
				std::cout << l[i][j];
			}
			std::cout << std::endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
	{
        int table[11][11]={0};
        if(n==0)
			break;
        for(int i=0,in;i<n;i++)
		{
            for(int j=0;j<n;j++)
			{
                cin>>in;
                table[i][j]=in;
                table[n][j]+=in;
                table[i][n]+=in;
            }
        }
        for(int i=0;i<n;i++)table[n][n]+=table[n][i];
        for(int i=0;i<n+1;i++)
		{
            for(int j=0;j<n+1;j++)
            printf("%5d",table[i][j]);
            cout<<endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include<vector>
using namespace std;
int main()
{
	while(1)
	{
		int N;
		cin >> N;
		if(N == 0)
		{
			return 0;
		}

		vector<vector<int>> map;

		//??????????????????
		for(int i = 0; i < N+1; i++)
		{
			vector<int> column;
			for(int j = 0; j < N + 1; j++)
			{
				if(i == N)
				{
					column.push_back(0);
				}
				else if(j != N)
				{
					int value;
					cin >> value;
					column.push_back(value);
				}
				else
				{
					column.push_back(0);
				}

			}  
			map.push_back(column);
		}
		//?????????????¨????
		int totalSum = 0;
		//????????????????¨????
		for(int i = 0; i < N; i++)
		{
			int sum = 0;
			for(int j = 0; j < N; j++)
			{
				sum += map[i][j];
			}
			map[i][N] = sum;
		}
		//????????????????¨????
		for(int i = 0; i < N; i++)
		{
			int sum = 0;
			for(int j = 0; j < N; j++)
			{
				sum += map[j][i];
			}
			map[N][i] = sum;
			totalSum += sum;
		}
		//????????????????¨???????????????£??\
		map[N][N] = totalSum;

		for(int i = 0; i < N + 1; i++)
		{
			for(int j = 0; j < N + 1; j++)
			{
				cout << setw(5) << right << map[i][j];
			}
			cout << endl;
		}
	}

}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int n;
int t[11][11];
int main(){
  while(cin>>n){
    if(n==0)break;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>t[i][j];
      }
    }
    for(int j=0;j<n;j++){
      t[n][j]=0;
      for(int i=0;i<n;i++){
	t[n][j]+=t[i][j];
      }
    }
    for(int i=0;i<=n;i++){
      t[i][n]=0;
      for(int j=0;j<n;j++){
	t[i][n]+=t[i][j];
      }
    }

    for(int i=0;i<=n;i++){
      
      for(int j=0;j<=n;j++){
	if(j)cout<<' ';
	printf("%5d",t[i][j]);
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>
int d[10][10];
int t[10][10];
int n;
int i,j;
int res;

int main(){
	while(1){
	scanf("%d",&n);
	if(n==0)return 0;
	for(i=0;i<n;i++)for(j=0;j<n;j++){
		scanf("%d",&d[i][j]);
		t[i][j]=0;
	}
	for(i=0;i<n;i++){
		res=0;
		for(j=0;j<n;j++){
			res+=d[i][j];
			printf("%5d",d[i][j]);
		}
		printf("%5d\n",res);
	}
	for(i=0;i<n;i++){
		res=0;
		for(j=0;j<n;j++){
			res+=d[j][i];
		}
		printf("%5d",res);
	}
	res=0;
	for(i=0;i<n;i++)for(j=0;j<n;j++){
		res+=d[i][j];
	}
	printf("%5d\n",res);
	}
}

C++: #include <stdio.h>
int main(){
    int n,a[100][100],tot;
    while(1){
        scanf("%d",&n);
        if(n==0)return 0;
        for(int i=0;i<n;i++){
            tot=0;
            for(int j=0;j<n;j++){
                scanf("%d",&a[i][j]);
                tot+=a[i][j];
            }
            a[i][n]=tot;
        }
        for(int j=0;j<=n;j++){
            tot=0;
            for(int i=0;i<n;i++){
                tot+=a[i][j];
            }
            a[n][j]=tot;
        }
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                printf("%5d",a[i][j]);
            }
            printf("\n");
        }
    }
}

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++){
                cout << aa[i][j];
                if(j<n)cout << ' ';
            }
            cout << endl;
        }
    }
     cout << endl;


}

C++: #include <cstdio>
#include <vector>
using namespace std;
int main() 
{
    int n;
    while (scanf("%d",&n)&&n!=0) {
        vector<vector<int> > map;
        for (int i=0; i<n; i++) {
            vector<int> in(n+1);
            in[n]=0;
            for (int j=0; j<n; j++) {
                scanf("%d",&in[j]);
                in[n]+=in[j];
            }
            map.push_back(in);
        }
        vector<int> sum(n+1,0);
        for (int i=0; i<n+1; i++) {
            for (int j=0; j<n; j++) {
                sum[i]+=map[j][i];
            }
        }
        map.push_back(sum);
        for (int i=0; i<n+1; i++) {
            for (int j=0; j<n+1; j++) {
                if (j!=0) printf(" ");
                printf("%5d",map[i][j]);
            }
            printf("\n");
        }
    }
}