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(){
        int N;
        while(true){
        cin >> N;
        if(N==0)
                break;
        int table[100][100];
        for(int i=0 ; i<N ; i++ ){
                int sum=0;
                for(int j=0 ; j<N ; j++ ){
                        cin >> table[i][j];
                        sum+=table[i][j];
                }
                table[i][N]=sum;
        }
        for(int i=0 ; i<=N ; i++ ){
                table[N][i]=0;
                for(int j=0 ; j<N ; j++ ){
                        table[N][i]+=table[j][i];
                }
        }
        for(int i=0 ; i<=N ; i++ ){
                for(int j=0 ; j<=N ; j++ ){
                        int space=0;
                        if(table[i][j]<10)
                                space=4;
                        else if(table[i][j]<100)
                                space=3;
                        else if(table[i][j]<1000)
                                space=2;
                        else if(table[i][j]<10000)
                                space=1;
                        for(int l=0 ; l<space ; l++ )
                                cout<<" ";
                        cout << table[i][j];
                //      if(j!=N)
                //              cout<<" ";
                }
                cout << endl;
        }
        }
        return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n;
	int i,j;
	int data[11][11];
	
	scanf("%d",&n);
	while(n!=0){

		for(j=0;j<=n;j++){
			data[n][j]=0;
		}
		for(i=0;i<n;i++){
			data[i][n]=0;
			for(j=0;j<=n-1;j++){
				scanf("%d",&data[i][j]);
				data[i][n] += data[i][j];
				data[n][j] += data[i][j];
				data[n][n] += data[i][j];
			}
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d",data[i][j]);
			}
		printf("\n");
		}
	scanf("%d",&n);
	}
	return 0;
}

C++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
template<class _T>
inline void _prfe(const char *_n, _T _c, bool _p = false){
    ITER(_c) _it=_c.begin();
    if(_p){ cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{ cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

int main(){
    int n, m;
    while(cin >> n){
        if(n == 0) break;

        int t[11][11];
        FILL(t,0);
        REP(y,n) REP(x,n){
            cin >> m;
            t[y][x] = m; t[y][n] += m; t[n][x] += m; t[n][n] += m;
        }
        REP(y,n+1){
            REP(x,n+1){
                printf("%5d", t[y][x]);
            }
            printf("\n");
        }
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(true){
  cin>>n;
  if(!n)break;
  int table[n+1][n+1];
  for(int y=0;y<n;y++){
    int s = 0;
    for(int x=0;x<n;x++){
      cin>>table[x][y];
      s+=table[x][y];
    }
    table[n][y] = s;
  }
  for(int x=0;x<n+1;x++){
    int s = 0;
    for(int y=0;y<n;y++){
      s+=table[x][y];
    }
    table[x][n] = s;
  }
  for(int y=0;y<n+1;y++){
    for(int x=0;x<n;x++){
      printf("%4d ",table[x][y]);
    }
    printf("%4d\n",table[n][y]);
  }
  }
  return 0;
}

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

int log10(int n) {
	int keta = 0;
	while (n > 0) {
		n /= 10;
		keta++;
	}
	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-log10(table[i][j]);k++) {
					printf(" ");
				}
				printf("%d", table[i][j]);
			}
			printf("\n");
		}
	}

	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,all;
    for(;;){
    int glap[12][12]={0};
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>glap[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            glap[i][n]+=glap[i][j];
            glap[n][i]+=glap[j][i];
        }
    }
    for(int i=0;i<n;i++){
        glap[n][n]+=glap[n][i];
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            printf("%5d",glap[i][j]);
        }
        cout<<endl;
    }
    }
}