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 <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) break;
    int v[n + 1][n + 1];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> v[i][j];
      }
    }
    // x
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = 0; j < n; j++) {
        sum += v[i][j];
      }
      v[i][n] = sum;
    }
    // y
    for (int j = 0; j < n; j++) {
      int sum = 0;
      for (int i = 0; i < n; i++) {
        sum += v[i][j];
      }
      v[n][j] = sum;
    }
    int k = 0;
    for (int i = 0; i < n; i++) {
      k += v[n][i];
    }
    v[n][n] = k;

    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= n; j++) {
        if (j == n) {
          cout << setw(5) << right << v[i][j] << endl;
        } else {
          cout << setw(5) << right << v[i][j] << " ";
        }
      }
    }

  }
}

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

int main() {
  int field[100][100];
  int n,x;
  while (cin >> n) {
    if(n == 0) break;
    int field[100][100] = {0};
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        cin >> x;
        field[i][j] = x;
      }
    }
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        field[i][n] += field[i][j];
      }
    }
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        field[n][i] += field[j][i];
      }
    }
    for(int i=0;i<n;i++) {
      field[n][n] += field[i][n];
    }
    for(int i=0;i<n+1;i++) {
      for(int j=0;j<n+1;j++) {
        printf("%5d",field[i][j]);
      }
      cout <<  endl;
    }
  }
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int data[150][150] = { 0 };

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

		}
		for (int i = 0;i < n+1;i++) {
			for (int j = 0;j < n+1;j++) {
				cout << data[i][j]<<" ";
			}
			cout << endl;
		}
		

	}

}

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

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

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

int main(){
int N,num[11][11]={},x;
int a;
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++)
{
a =5-( (int)log10((double)(num[i][j]) )+ 1);
for(int k=0;k<a;k++)
{cout<<" ";}
cout<<num[i][j];}
cout<<endl;


}

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


}

return 0;
}

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

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl


int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( n == 0 )
		{
			break;
		}

		vector< vector<int> > table;

		REP( i, 0, n )
		{
			table.PB( vector<int>() );
			int sum = 0;

			REP( j, 0, n )
			{
				int in;
				cin >> in;
				table[i].PB( in );
				sum += in;
			}

			table[i].PB( sum );
		}

		table.PB( vector<int>() );

		REP( i, 0, n + 1 )
		{
			int sum = 0;

			REP( j, 0, n )
			{
				sum += table[j][i];
			}

			table[n].PB( sum );
		}

		REP( i, 0, table.size() )
		{
			REP( j, 0, table[i].size() )
			{
				printf("%5d%c", table[i][j], ( j + 1 == table[i].size() ? '\n' : ' ' ) );
			}
		}
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n;
	short matrix[11][11];

	while(cin >> n, n)
	{
		for(int i=0; i < n; i++) matrix[n][i] = matrix[i][n] = 0;
		for(int y=0; y < n; y++) {
			for(int x=0; x < n; x++) {
				cin >> matrix[y][x];
				matrix[n][x] += matrix[y][x];
				matrix[y][n] += matrix[y][x];
				matrix[n][n] += matrix[y][x];
			}
		}
		int nn = n + 1;
		for(int y=0; y < nn; y++) {
			for(int x=0; x < nn; x++) {
				if(x == nn)
					printf("%5d", matrix[y][x]);
				else
					printf("%5d ", matrix[y][x]);
			}
			printf("\n");
		}
	}

	return 0;
}

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

int main() {
	
	int n;
	int *elm;
	int sum,total;
	
	while(cin>>n,n){
		
		elm = new int[n*n];
		
		for(int i=0;i<n*n;++i){
			cin >> elm[i];
		}
		
		
		
		for( int i=0;i<n;++i){
			sum = 0;
			for(int j=0;j<n;++j){
				cout << setw(5) << elm[j+i*n];
				sum += elm[j+i*n];
			}
			cout << setw(5) << sum;
			cout << endl;
		}
		
		total = 0;
		for(int i=0;i<n;++i){
			sum = 0;
			for(int j=0;j<n;++j){
				sum += elm[j*n+i];
			}
			cout<<setw(5)<<sum;
			total += sum;
		}
		cout<<setw(5)<<total<<endl;
		delete[]elm;
	}
	return 0;
}