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 <iostream>
#include <iomanip>

using namespace std;

int main() {
	int num;
	while(cin>>num, !cin.eof()) {
		int table[num][num];
		int col_num[num];

		for(int i=0; i<num; i++){
			for(int j=0; j<num; j++){
				cin>>table[i][j];
			}
		}
		for(int i=0; i<num; i++){
			int row_sum = 0;
			for(int j=0; j<num; j++){
				cout<< setw(5)<<right <<table[i][j]<<" ";
				row_sum+=table[i][j];
				col_num[j] += table[i][j];
			}
			cout<<row_sum<<endl;
		}
		for(int i=0; i<num; i++){
			cout<< setw(5)<<right<< col_num[num];
		}
	}
	return 0;
}

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

int main(){
	int n;
	while (cin >> n) {
		if (n == 0) { break; }
		int x, y, a[15][15] = {};
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j <= n; j++) {
				if (j == n) {
					a[i][n] = sum;
					continue;
				}
				cin >> a[i][j];
				sum += a[i][j];
			}
		}
		for (int i = 0; i<n; i++) {
			for (int j = 0; j <= n; j++) {
				a[n][j] += a[i][j];
			}
		}
		for (int i = 0; i<=n; i++) {
			for (int j = 0; j <= n; j++) {
				int k;
				if (a[i][j] != 0) {
					k = log10(a[i][j]);
					k = 4 - k;
				}
				else{
					k = 4;
				}
				for(int z = 0; z < k; z++){
					cout << " ";
				}
				cout << a[i][j];
			}

			cout << endl;
		}
	}
	return 0;
}

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

const int MAXN = 11;
int n;
int g[MAXN][MAXN];

int getSum(int i, int j, int ei, int ej) {
  int sum = 0;
  for(; i < ei; ++i) {
    for(; j < ej; ++j) {
      sum += g[i][j];
    }
  }
  return sum;
}

int main() {
  while(cin >> n && n) {
    for(int i = 0; i < n; ++i) {
      for(int j = 0; j < n; ++j) {
        cin >> g[i][j];
      }
    }
    for(int i = 0; i < n+1; ++i) {
      for(int j = 0; j < n+1; ++j) {
        int value = 0;
        if(i == n && j == n) {
          value = getSum(0, 0, n, n);
        } else if(i == n) {
          value = getSum(0, j, n, j+1);
        } else if(j == n) {
          value = getSum(i, 0, i+1, n);
        } else {
          value = g[i][j];
        }
        printf("%5d", value);
      }
      printf("\n");
    }
  }
  return 0;
}

C++: #include <cstdio>

int main(){
  int n;
  
  while(1){
    scanf("%d", &n);
    if(!n) break;
    
    int table[11][11] = {0};
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	scanf("%d", &table[i][j]);
      }
    }
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	table[i][n] += table[j][i];
	table[n][i] += table[i][j];
      }
    }
    
    for(int i=0; i<n; i++)
      table[n][n] += table[n][i];
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++)
	printf("%5d", table[i][j]);
      putchar('\n');
    }
  }
    
  return 0;
}

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

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	while (cin >> n, n){
		vector<vector<int>> hyou(n + 1, vector<int>(n + 1, 0));
		REP(i, n){
			REP(j, n){
				int num;
				cin >> num;
				hyou[i][j] = num;
			}
		}
		REP(i, n){
			REP(j, n){
				hyou[i][n] += hyou[i][j];
			}
		}
		REP(j, n){
			REP(i, n){
				hyou[n][j] += hyou[i][j];
			}
		}
		REP(i, n){
			hyou[n][n] += hyou[i][n];
		}
		REP(i, n + 1){
			REP(j, n + 1){
				printf("%5d", hyou[i][j]);
			}
			printf("\n");
		}
	}
}

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

using namespace std;

int main() {
    
    int n;
    while (cin >> n) {
    
    if(n == 0)
    break;
    
    int A[51][51] = {};
    
    for(int i=0;i<n;i++) { 
    for(int j=0;j<n;j++) {
    	
    	cin >> A[i][j];
    	
    	A[i][n] += A[i][j];
    	A[n][j] += A[i][j];
	}
	A[n][n] += A[i][n];
}

	for(int i=0;i<=n;i++) { 
    for(int j=0;j<n;j++) {
    	
    	cout << setw(5)<< A[i][j];
    }
	cout << setw(5)<< A[i][n];
	cout << "\n";
}
}
    return 0;
}

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

int a[11][11];

void init() {
  for(int i = 0; i < 11; ++i) {
	for(int j = 0; j < 11; ++j) {
	  a[i][j] = 0;
	}
  }
}

void Comp(int n) {
  for(int i = 0; i <= n; ++i) {
	for(int j = 0; j < n; ++j) {
	  a[i][n] += a[i][j];
	  a[n][j] += a[i][j];
	}
  }
}

void print(int n) {
  for(int i = 0; i <= n; ++i) {
	for(int j = 0; j <= n; ++j) {
	  cout << right << setw(5) << a[i][j];
	  cout << (j < n ? " " : "\n");
	}
  }
}

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

	init();
	for(int i = 0; i < n; ++i) {
	  for(int j = 0; j < n; ++j) {
		cin >> a[i][j];
	  }
	}
	Comp(n);
	print(n);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#define MAX_N 110
using namespace std;
int main(){
	int n,i,j;
	int a[MAX_N][MAX_N];
	while(1){
		cin >> n;
		if(n==0)break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				cin >> a[i][j];
			}
		}

		int sum1=0,sum[MAX_N];
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				sum[j]+=a[i][j];
				if(i==n){
					a[i][j]=sum[j];
					sum[j]=0;
				}

				sum1+=a[i][j];
				if(j==n){
					a[i][j]=sum1;
					sum1=0;
				}
			}
		}

		for(i=0;i<=n;i++){
			for(j=0;j<n;j++){
				printf("%5d",a[i][j]);
			}
			printf("%5d\n",a[i][n]);
		}

	}
	return 0;
}

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++) {
				if (data[i][j] < 10) {
					cout << "    " << data[i][j];
				}
				else if (data[i][j] < 100) {
					cout << "   " << data[i][j];
				}
				else if (data[i][j] < 1000) {
					cout << "  " << data[i][j];
				}
			}
			cout << endl;
		}
		

	}
	return 0;

}