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

int main(){
	double num[12][12]={};
	int N ;
int a=0;
while(1)
{cin>>N;
if(N==0)break;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++)
{cin>>num[i][j];num[i][N]+=num[i][j];}
}
for(int i=0;i<N;i++)
num[N][N]+=num[i][N];
for(int i=0;i<N;i++)
	for(int j=0;j<N;j++)
num[N][i]+=num[j][i];

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++)
{
	printf("5%lf",num[i][j]);}
cout<<endl;}



for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){
num[i][j]=0;
}
}


}
 
return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int graph[128][128];
	int num;
	
	while(cin >> num)
	{
		if(!num) break;
		int count = 0;
		int all = 0, las[128];
		for(int i = 0; i < 128; i++)
			las[i] = 0;

		for(int i = 0; i < num; i++)
		{
			for(int j = 0; j < num; j++)
			{
				cin >> graph[i][j];
				count += graph[i][j];
				las[j]  += graph[i][j];
				all += graph[i][j];
				if(j == num - 1) 
				{
					graph[i][j+1] = count;
					count = 0;
				}
				if(i == num - 1)
				{
					graph[i+1][j] = las[j];
				}
				if(i == num - 1 && j == num - 1)
				{
					graph[i+1][j+1] = all;
				}
			}
		}

		for(int i = 0; i < num + 1; i++)
		{
			for(int j = 0; j < num + 1; j++)
			{
				printf("%5d", graph[i][j]);
			}
			puts("");
		}

	}
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int a[100][100];
int n;
int tmp;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(cin >> n,n){
		int x[100];
		rep(i,100) x[i] = 0;
		int sum;
		rep(i,n){
			sum = 0;
			rep(j,n){
				cin >> a[i][j];
				tmp = 10000;
				rep(k,4){
					if(a[i][j]/tmp!=0) break;
					cout << " ";
					tmp /= 10;
				}
				cout << a[i][j];
				sum += a[i][j];
				x[j] += a[i][j];
			}
			tmp = 10000;
			rep(k,4){
				if(sum/tmp!=0) break;
				cout << " ";
				tmp /= 10;
			}
			cout << sum << endl;
		}
		sum = 0;
		rep(i,n){
			sum += x[i];
			tmp = 10000;
			rep(k,4){
				if(x[i]/tmp!=0) break;
				cout << " ";
				tmp /= 10;
			}
			cout << x[i];
		}
		tmp = 10000;
		rep(k,4){
			if(sum/tmp!=0) break;
			cout << " ";
			tmp/=10;
		}
		cout << sum << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

int matrix[16][16];

int main(){
    int n,i,j;

    while( cin >> n, n ){
        // input
        rep(i,n) rep(j,n) cin >> matrix[i][j];

        // yoko
        rep(i,n){
            int yoko = 0;
            rep(j,n) yoko += matrix[i][j];
            matrix[i][n] = yoko;
        }

        // tate
        rep(j,n){
            int tate = 0;
            rep(i,n) tate += matrix[i][j];
            matrix[n][j] = tate;
        }

        int sum = 0;
        rep(i,n) sum += matrix[i][n];
        matrix[n][n] = sum;

        // output
        rep(i,n+1){
            rep(j,n+1){
                printf("%5d",matrix[i][j]);
            }
            puts("");
        }
    }

    return 0;
}

C++: #include<iostream>

using namespace std;

int main(void) {
	int n, tmp, sum, suml[10];
	int i, j;

	while(true) {
		cin >> n;
		if( n == 0) { break; }
		for(i = 0; i < 10; i++) {
			suml[i] = 0;
		}
		for(i = 0; i < n; i++) {
			sum = 0;
			for(j = 0; j < n; j++) {
				cin >> tmp;
				cout << tmp << " ";
				suml[j] += tmp;
				sum += tmp;
			}
			cout << sum << endl;
		}
		sum = 0;
		for(i = 0; i < n; i++) {
			cout << suml[i] << " ";
			sum += suml[i];
		}
		cout << sum << endl;
	}

	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int n;
  while (cin >> n){
    int table[n][n], x[5] = {0}, y[n] = {0};
    REP(i, n){
      REP(j, n) cin >> table[i][j];
    }
    REP(i, n){
      cout << setw(4) << right << table[i][0];
      x[i] = table[i][0];
      FOR(j, 1, n){
        cout << setw(4) << right << table[i][j];
        x[i] += table[i][j];
      }
      cout << setw(4) << right << x[i] << endl;
    }
    REP(i, n){
      REP(j, n) y[i] += table[j][i];
    }
    cout << setw(4) << right << y[0];
    FOR(i, 1, n) cout << setw(4) << right << y[i];
    cout << setw(4) << right << x[0] + x[1] + x[2] + x[3] + x[4] << endl;
  }
}

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;


}