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<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];
        }
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                for(int k=keta(a[i][j]);k<5;k++){
                    cout<<" ";
                }
                cout<<a[i][j];
            }
            cout<<endl;
        }
    }
	return 0;
}

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

int main() {
	int m[11][11];
	int n;
	while (cin >> n, n) {
		memset(m, 0, sizeof(m));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> m[i][j];
				m[n][j] += m[i][j];
				m[i][n] += m[i][j];
				m[n][n] += m[i][j];
			}
		}
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				printf("%5d", m[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >>n&&n){
    vector<vector<int>> v(n+1,vector<int>(n+1,0));
    rep(i,n){
      rep(j,n){
        cin >> v[j][i];
      }
    }
    rep(i,n){
      int sum = 0;
      rep(j,n){
        scout(5)<< v[j][i] ;
        sum += v[j][i];
      }
      v[n][i] = sum;
      scout(5)<< sum << endl;
    }
    rep(i,n+1){
      int sum = 0;
      rep(j,n){
        sum += v[i][j];
      }
      scout(5)<< sum ;
    }
    cout << endl;
  }
  return 0;
}

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

int main(){
	int data[11][11];
	int n;
	cin >> n;
	while (n){

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}
		int sum_col[10] = { 0 };
		int sum_low[10] = { 0 };

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sum_col[i] += data[i][j];
				sum_low[i] += data[j][i];
			}
			data[i][n] = sum_col[i];
			data[n][i] = sum_low[i];
		}
		int sum = 0;
		for (int i = 0; i < n; i++){
			sum += data[i][n];
		}
		data[n][n] = sum;
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n + 1; j++){
				cout << setw(5) << right << data[i][j];
			}
			if (i != n)	cout<<"\n";
		}
		cin >> n;
	}
	
	return 0;	
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int stage[12][12] = {{0}};
    int n;
    int j = 0;
    int x = 0,y = 0,xx = 0;
    for(;;){
        cin >> n;
        if(n == 0)break;
        for(int i = 0;i < n; i++){
            for(j = 0;j < n; j++){
                cin >> stage[i][j];
                x += stage[i][j];
                if(j == n-1){
                    stage[i][n] = x;
                    xx += stage[i][n];
                    x = 0;
                }
            }
        }
        for(int i = 0;i < n; i++){
            for(j = 0;j < n; j++){
                y += stage[j][i];
                if(j == n-1){
                    stage[n][i] = y;
                    y = 0;
                }
            }
        }
        stage[n][n] = xx;
        for(int i = 0;i <= n; i++){
            for(int j = 0;j <= n; j++){
                printf("%5d",stage[i][j]);
            }
            printf("\n");
        }
        x = 0,y = 0,xx = 0;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
#define MAX 11

int main(){
    int n,mat[MAX][MAX];
    
    while(true){
        for(int i = 0 ; i < MAX ; i++)
            for(int j = 0 ; j < MAX ; j++)
                mat[i][j] = 0;
        
        cin >> n;
        if(!n) break;
        
        for(int i = 0 ; i < n ; i++)
            for(int j = 0 ; j < n ; j++)
                cin >> mat[i][j];
        
        int sum = 0;
        for(int i = 0 ; i <= n ; i++){
            for(int j = 0 ; j <= n ; j++){
                sum += mat[i][j];
                if(j == n){
                    mat[i][j] = sum;
                    sum = 0;
                }
                
            }
        }
        
        for(int j = 0 ; j <= n ; j++){
            for(int i = 0 ; i <= n ; i++){
                sum += mat[i][j];
                if(i == n){
                    mat[i][j] = sum;
                    sum = 0;
                }
            }
        }
        
        int e = 0;
        for(int i = 0 ; i < n ; i++){
            e += mat[n][i];
            if(i == n-1) mat[n][n] = e;
        }
        
        for(int i = 0 ; i <= n ; i++){
            for(int j = 0 ; j <= n ; j++){
                 printf("%5d" ,mat[i][j]);
            }
            cout << endl;
        }
    }
    
    return 0;
}