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>

#define MAX 16

int main(void){
	int a[MAX][MAX];
	int n;
	
	while (scanf("%d", &n), n){
		for (int i=0; i<=n; i++) a[n][i] = a[i][n] = 0;
		for (int i=0; i<n; i++){
			for (int j=0; j<n; j++){
				scanf("%d", &a[i][j]);
				a[i][n] += a[i][j];
				a[n][j] += a[i][j];
				a[n][n] += a[i][j];
			}
		}
		for (int i=0; i<=n; i++){
			for (int j=0; j<=n; j++){
				printf("%5d",a[i][j]);
			}
			puts("");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios_base::sync_with_stdio(0);
  int n;
  while(cin >> n, n){
    vector< vector<int> > mt;
    for(int i = 0; i < n; i++){
      vector<int> c;
      int sum = 0;
      for(int j = 0; j < n; j++){
        int a;  cin >> a;
        c.push_back(a);
        sum += a;
      }
      c.push_back(sum);
      mt.push_back(c);
    }
    vector<int> lc;
    for(int i = 0; i < n + 1; i++){
      int sum = 0;
      for(int j = 0; j < n; j++) sum += mt[j][i];
      lc.push_back(sum);
    }
    mt.push_back(lc);
    for(int i = 0; i < n + 1; i++){
      for(int j = 0; j < n + 1; j++){
        if(j) cout << " ";
        cout << mt[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int ct,map[10][10],answer[11][11];
	while(1){
		scanf("%d",&ct);
		if(ct==0){
			return 0;
		}
		for(int f1=0;f1<11;f1++){
			for(int f2=0;f2<11;f2++){
				answer[f1][f2]=0;
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				scanf("%d",&map[f1][f2]);
				answer[f1][f2]=map[f1][f2];
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				answer[f1][ct]+=map[f1][f2];
				answer[ct][f1]+=map[f2][f1];
			}
		}
		for(int f1=0;f1<ct;f1++){
			answer[ct][ct]+=answer[f1][ct];
		}
		for(int f1=0;f1<ct+1;f1++){
			for(int f2=0;f2<ct+1;f2++){
				printf("%5d",answer[f1][f2]);
			}
			printf("\n");
		}
	}
	return 0;
}

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

int main()
{
    int n;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        int m[n+1][n+1];
        for( int i = 0; i < n + 1; i++ )
            for( int j = 0; j < n + 1; j++ )
                m[i][j] = 0;

        for( int i = 0; i < n; i++ )
            for( int j = 0; j < n; j++ )
                cin >> m[i][j];

        for( int i = 0; i < n; i++ )
        {
            int line = 0;
            for( int j = 0; j < n; j++ )
                line += m[i][j];
            m[i][n] = line;
            m[n][n] += m[i][n];
        }

        for( int i = 0; i < n; i++ )
        {
            int row = 0;
            for( int j = 0; j < n; j++ )
                row += m[j][i];
            m[n][i] = row;
        }

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

    return 0;
}

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

int main(){
	int n,i,j;
	while(cin >> n && n){
		int table[11][11] = {{0}};
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				cin >> table[i][j];
				table[i][n] += table[i][j];
				table[n][i] += table[i][j];
			}
			table[n][n] += table[i][n];
		}
		for(i = 0;i <= n;i++){
			for(j = 0;j <= n;j++){
				if(table[i][j] / 100 == 0) cout << "   ";
				else cout << "  ";
				cout << table[i][j];
			}
			cout << "\n";
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  int M[12][12];
  while(cin>>n,n){
    rep(i,n)rep(j,n)cin>>M[i][j];
    cout<<endl;
    rep(i,n){
      int tmp=0;
      rep(j,n)tmp+=M[i][j];
      M[i][n]=tmp;
    }
    rep(i,n){
      int tmp=0;
      rep(j,n)tmp+=M[j][i];
      M[n][i]=tmp;
    }
    int tmp=0;
    rep(i,n)tmp+=M[n][i];
    M[n][n]=tmp;
    rep(i,n+1){
      rep(j,n+1){
        cout<<M[i][j];
        if(j<n+1)cout<<' ';
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int matrix[11][11];

int main()
{
	int n,sum;
	
	for(;;)
	{
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cin>>matrix[i][j];
			}
		}

		for(int i=0;i<n;i++)
		{
			sum=0;
			for(int j=0;j<n;j++)
			{
				sum+=matrix[i][j];
			}
			matrix[i][n]=sum;
		}
		for(int j=0;j<n;j++)
		{
			sum=0;
			for(int i=0;i<n;i++)
			{
				sum+=matrix[i][j];
			}
			matrix[n][j]=sum;
		}
		sum=0;
		for(int i=0;i<n;i++)
		{
			sum+=matrix[i][n];
		}
		matrix[n][n]=sum;
		
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=n;j++)
			{
				if(j>0)cout<<' ';
				cout<<matrix[i][j];
			}
			cout<<endl;
		}
	}
}

C++: 
#include <iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(){
    int a[10][10],n,i,j,tate[10]={0},yoko[10]={0},sum=0;
    while(cin>>n){
        if(n==0)break;
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                cin>>a[i][j];
                sum+=a[i][j];
                yoko[i]+=a[i][j];
                tate[j]+=a[i][j];
            }
        }
        for(i=0;i<n;i++){
            for(j=0;j<=n;j++){
                if(j==n)printf("%5d\n",yoko[i]);
                else printf("%5d",a[i][j]);
            }
        }
        for(j=0;j<=n;j++){
            if(j!=n)printf("%5d",tate[j]);
            else if(j==n)printf("%5d\n",sum);
        }
        for(i=0;i<10;i++){
            tate[i]=0;
            yoko[i]=0;
        }
        sum=0;
    }
     return 0;
}