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<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int n=0,i=0,j=0,k=0,sum=0,ii=0;

        int aa[128][128];
    for(ii=0;;ii++){
            //int bb[]={};
        cin >> n;
        if(n==0)break;
        //if(n==0 && x==0)break;
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                cin >> k;
                aa[i][j]=k;
                sum+=k;
            }
            aa[i][j]=sum;
            sum=0;
        }


        for(j=0;j<n+1;j++){
            for(i=0;i<n;i++){
                sum+=aa[i][j];
            }
        aa[i][j]=sum;
        sum=0;
        }
        for(i=0;i<n+1;i++){
            for(j=0;j<n+1;j++){
                if(aa[i][j]<10000)cout << ' ';
                if(aa[i][j]<1000)cout << ' ';
                if(aa[i][j]<100)cout << ' ';
                if(aa[i][j]<10)cout << ' ';
                cout << aa[i][j];
            }
            cout << endl;
        }
    }
    //cout << endl;


}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n;
	while(cin>>n,n){
		int a[11][11]={0};
		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++){
			for(int j=0;j<n;j++){
				a[i][n]+=a[i][j];
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				a[n][i]+=a[j][i];
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;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]);
			}
			cout<<endl;
		}
	}
}

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

int main(){
    while(true){
        int sheet[11][11] = {};
        int size; cin >> size;
        if(size == 0) return 0;
        
        // get
        for(int i=0; i<size; i++){
            int col_sum = 0;
            for(int j=0; j<size; j++){
                cin >> sheet[i][j];
                col_sum += sheet[i][j];
            }
            sheet[i][size] = col_sum;
        }
        
        // show
        for(int i=0; i<size; i++){
            for(int j=0; j<size+1; j++){
                cout << right << setw(5) << sheet[i][j];
            }
            cout << endl;
        }
        // row sum
        for(int i=0; i<size+1; i++){
            int row_sum = 0;
            for(int j=0; j<size; j++){
                row_sum += sheet[j][i];
            }
            cout << right << setw(5) << row_sum;
        }
        cout << endl;
    }
    return 0;
}

C++: 4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
4
52 96 15 20
86 22 35 45
45 78 54 36
16 86 74 55
0

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

int main()
{
	while (true) {
		int size;
		std::cin >> size;
		if (size == 0) break;
		
		int** table = new int*[size+1];
		for (int i=0; i<size+1; i++) {
			table[i] = new int[size+1];
		}
		
		for (int i=0; i<size; i++) {
			for (int j=0; j<size; j++) {
				std::cin >> table[i][j];
			}
		}
		
		for (int i=0; i<size; i++) {
			int row_sum = 0;
			for (int j=0; j<size; j++) row_sum += table[i][j];
			table[i][size] = row_sum;
		}
		for (int j=0; j<=size; j++) {
			int column_sum = 0;
			for (int i=0; i<size; i++) column_sum += table[i][j];
			table[size][j] = column_sum;
		}
		
		for (int i=0; i<=size; i++) {
			for (int j=0; j<=size; j++) {
				std::cout.setf(std::ios::right, std::ios::adjustfield);
				std::cout << std::setw(5) << table[i][j];
			}
			std::cout << std::endl;
		}
		
		for (int i=0; i<size+1; i++) delete[] table[i];
		delete[] table;
	}
	
	return 0;
}

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

int main(){
	int n,i,j;
	bool flag = false;
	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][j] += table[i][j];
			}
			table[n][n] += table[i][n];
		}
		if(flag) cout << "\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";
		}
		flag = true;
	}
	return 0;
}

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

int main(){
  int n;

  while(cin>>n,n){
    int t[n+1][n+1];
    memset(t,0,sizeof(t));
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        cin>>t[i][j];
        t[i][n] += t[i][j];
        t[n][j] += t[i][j];
        t[n][n] += t[i][j];
      }
    }

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

C++: #include <iostream>
#include <cstdio>
const int MAX_N = 10;
using namespace std;

int main(void) {
  int n;
  while (1) {
    cin >> n;
    if (n == 0) break;
    int masu[MAX_N + 1][MAX_N + 1];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cin >> masu[i][j];
      }
    }

    for (int i = 0; i < n; i++) {
      int tmp = 0;
      for (int j = 0; j < n; j++) {
        tmp += masu[i][j];
      }
      masu[i][n] = tmp;
    }
    for (int i = 0; i < n; i++) {
      int tmp = 0;
      for (int j = 0; j < n; j++) {
        tmp += masu[j][i];
      }
      masu[n][i] = tmp;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
      sum += masu[n][i];
    }
    masu[n][n] = sum;

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

  return 0;
}

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

int main(){
	int data[11][11];
	int n;
	cin >> n;
	while (n){

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

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sum_col[i] += data[i][j];
				sum_low[i] += data[j][i];
			}
			data[i][n] = sum_col[i];
			data[n][i] = sum_low[i];
		}
		int sum = 0;
		for (int i = 0; i < n; i++){
			sum += data[i][n];
		}
		data[n][n] = sum;
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n + 1; j++){
				cout << setw(5) << right << data[i][j];
			}
			if (i != n)	cout<<"\n";
		}
		cin >> n;
		if (n) cout<<"\n";
	}
	
	return 0;	
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while (cin >> n, n){
        int v[10] = {};
        rep(i, n){
            int s = 0;
            rep(j, n){
                int t; cin >> t;
                printf("%5d", t);
                s += t;
                v[j] += t;
            }
            printf("%5d\n", s);
        }
        int s = 0;
        rep(i, n){
            printf("%5d", v[i]);
            s += v[i];
        }
        printf("%5d\n", s);
    }
}