Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}

		a := make([][]int, n+1)
		for i := 0; i < n; i++ {
			sum := 0
			stdin.Scan()
			a[i] = make([]int, n+1)
			str := strings.Split(stdin.Text(), " ")
			for j := 0; j < n; j++ {
				a[i][j], _ = strconv.Atoi(str[j])
				sum += a[i][j]
				fmt.Printf("%5d", a[i][j])
			}
			a[i][n] = sum
			fmt.Printf("%5d\n", a[i][n])
		}
		a[n] = make([]int, n+1)
		for i := 0; i <= n; i++ {
			sum := 0
			for j := 0; j < n; j++ {
				sum += a[j][i]
			}
			a[n][i] = sum
			fmt.Printf("%5d", a[n][i])
		}
		fmt.Println()
	}
}

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>

using namespace std;

int h[12][12];
int n;
int sum[2][12];

int main()
{
  while(true)
  {
    for(int i = 0; i < 12; i++)
    {
      for(int j = 0; j < 12; j++)
        h[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", &h[i][j]);
    }
    for(int i = 0; i <= n; i++)
    {
      for(int j = 0; j <= n; j++)
      {
        printf("%5d", h[i][j]);
        h[i][n] += h[i][j];
        if(j != n)
        h[n][j] += h[i][j];
      }
      printf("\n");
    }
  }
  return 0;
}

C++: #include <stack>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int main() {
    
    int n;
    while(cin >> n && n != 0)
    {
        int a[11][11];
        for(int i = 0;i < n;i++)
        {
            for(int j = 0; j<n;j++)
            {
                cin >> a[i][j];
            }
        }
        for(int i = 0; i<n;i++)
        {
            a[i][n] = 0;
            a[n][i] = 0;
            for(int j = 0;j < n;j++)
            {
                a[i][n] += a[i][j];
                a[n][i] += a[j][i];
            }
        }
        a[n][n] = 0;
        for(int i = 0;i<n;i++)
        {
            a[n][n] += a[i][n];
        }
        for(int i = 0; i< n+1;i++)
        {
            for(int j = 0; j<n+1;j++)
            {
                cout << setw(5) << right << a[i][j];
            }
            cout <<endl;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

int main(){
	int n;
	int data[20][20];
	while(cin>>n){
		if(n==0)break;
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++){
				data[i][j]=0;
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>data[i][j];
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				data[i][n]=data[i][n]+data[i][j];
				data[n][j]=data[n][j]+data[i][j];
			}
		}
		for(int i=0;i<n;i++){
			data[n][n]=data[n][n]+data[i][n];
		}
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++){
				printf("%5d",data[i][j]);
			}printf("\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;
}