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 <stdio.h>

using namespace std;

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

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int N;
    while(cin>>N,N){
        int num[150][150]={{0}};
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                cin>>num[i][j];
                num[i][N]+=num[i][j];
                num[N][j]+=num[i][j];
                num[N][N]+=num[i][j];
            }
        }
        for(int i=0;i<=N;i++){
            for(int j=1;j<=N;j++){
                if(num[i][j]<10){
                    for(int k=0;k<4;k++)cout<<" ";
                }
                else if(num[i][j]<100){
                    for(int k=0;k<3;k++)cout<<" ";
                }
                else if(num[i][j]<1000){
                    for(int k=0;k<2;k++)cout<<" ";
                }
                else if(num[i][j]<10000){
                    for(int k=0;k<1;k++)cout<<" ";
                }
                cout<<num[i][j];
            }
            cout<<endl;
        }
    }
    return 0;
}

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

int main(){
	int data_size;
	cin >> data_size;
	while (data_size){
		vector<vector<int>> data;
		vector<vector<int>> data_digit;
		data.resize((data_size + 1)*(data_size + 1));
		data_digit.resize((data_size + 1) * (data_size + 1));
		for (int i = 0; i < data_size; i++){
			data[i].resize(data_size + 1);
			data_digit[i].resize(data_size + 1);
			for (int j = 0; j < data_size; j++){
				cin >> data[i][j];
				int tmp = data[i][j];
				data_digit[i][j] = 0;
				while (tmp){
					tmp /= 10;
					data_digit[i][j]++;
				}
			}
		}
		data[data_size].resize(data_size + 1);
		data_digit[data_size].resize(data_size + 1);
		for (int i = 0; i < data_size; i++){
			int sum = 0;
			for (int j = 0; j < data_size; j++){
				sum += data[i][j];
			}
			data[i][data_size] = sum;
			int tmp = sum;
			data_digit[i][data_size] = 0;
			while (tmp){
				tmp /= 10;
				data_digit[i][data_size]++;
			}

		}
		for (int i = 0; i < data_size + 1; i++){
			int sum = 0;
			for (int j = 0; j < data_size; j++){
				sum += data[j][i];
			}
			data[data_size][i] = sum;
			int tmp = sum;
			data_digit[data_size][i] = 0;
			while (tmp){
				tmp /= 10;
				data_digit[data_size][i]++;
			}
		}

		for (int i = 0; i < data_size + 1; i++){
			for (int j = 0; j < data_size + 1; j++){
				for (int k = data_digit[i][j]; k < 5; k++){
					cout << " ";
				}
				cout << data[i][j];
			}
			cout << "\n";
		}
		cin >> data_size;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n;
int tb[11][11];

int main() {
	while (1) {
		cin >> n; if (n == 0) break;
		memset(tb, 0, sizeof(tb));
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> tb[i][j];
			}
		}
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				tb[i][n] += tb[i][j];
				tb[n][j] += tb[i][j];
				tb[n][n] += tb[i][j];
			}
		}
		
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				cout << setw(5) << tb[i][j];
			}
			cout << endl;
		}
	}	
	
	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.width(5);
				cout << tmp;
				suml[j] += tmp;
				sum += tmp;
			}
			cout.width(5);
			cout << sum << endl;
		}
		sum = 0;
		for(i = 0; i < n; i++) {
			cout.width(5);
			cout << suml[i];
			sum += suml[i];
		}
		cout.width(5);
		cout << sum << endl;
	}

	return 0;
}

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

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

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(true){
  cin>>n;
  if(!n)break;
  int table[n+1][n+1];
  for(int y=0;y<n;y++){
    int s = 0;
    for(int x=0;x<n;x++){
      cin>>table[x][y];
      s+=table[x][y];
    }
    table[n][y] = s;
  }
  for(int x=0;x<n+1;x++){
    int s = 0;
    for(int y=0;y<n;y++){
      s+=table[x][y];
    }
    table[x][n] = s;
  }
  for(int y=0;y<n+1;y++){
    for(int x=0;x<n+1;x++){
      printf("%5d",table[x][y]);
    }
    printf("\n");
  }
  }
  return 0;
}

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

using namespace std;

int main(){
  int mat[11][11];
  for(int n;cin>>n,n;){
    for(int y=0;y<n;y++){
      int s=0;
      for(int x=0;x<n;x++){
	cin>>mat[y][x];
	s+=mat[y][x];
      }
      mat[y][n]=s;
    }
    for(int x=0;x<=n;x++){
      int s=0;
      for(int y=0;y<n;y++){
	s+=mat[y][x];
      }
      mat[n][x]=s;
    }
    for(int y=0;y<=n;y++){
      for(int x=0;x<=n;x++){
	cout<<setw(5)<<right<<mat[y][x];
      }
      cout<<endl;
    }
  }
  return 0;
}

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

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		vector< vector<int> > Vec(N + 1, vector<int>(N + 1));
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				cin >> Vec[i][j];
			}
		}
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				Vec[i][N] += Vec[i][j];
				Vec[N][i] += Vec[j][i];
			}
		}
		for(int i = 0; i < N; ++i)
		{
			Vec[N][N] += Vec[i][N];
		}
		for(int i = 0; i < N + 1; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				printf("%5d", Vec[i][j]);
			}
			printf("%5d\n", Vec[i][N]);
		}
	}
}

int main()
{
	solve();
	return(0);
}