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 <cstdio>

using namespace std;

string disp(int a){
	string ans = "     ";
	if(a == 0){
		ans = "    0";
		return ans;
	}
	ans[0] = (a / 10000) + '0';
	ans[1] = (a / 1000) % 10 + '0';
	ans[2] = (a / 100) % 10 + '0';
	ans[3] = (a / 10) % 10 + '0';
	ans[4] = a % 10 + '0';
	
	for(int i = 0; i <= 4; i++){
		if(ans[i] == '0'){
			ans[i] = ' ';
		}else{
			break;
		}
	}
	
	return ans;
}

int main(){
	
	int n;
	
	int mat[20][20];
	
	cin >> n;
	
	while(n != 0){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> mat[i][j];
			}
		}
		
		int sum;
		
		for(int i = 0; i < n; i++){
			sum = 0;
			for(int j = 0; j < n; j++){
				sum += mat[i][j];
			}
			mat[i][n] = sum;
		}
		
		for(int j = 0; j <= n; j++){
			sum = 0;
			for(int i = 0; i < n; i++){
				sum += mat[i][j];
			}
			mat[n][j] = sum;
		}
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				cout << disp(mat[i][j]);
			}
			cout << endl;
		}
		
		cin >> n;
	}
	return 0;
}

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

int main()
{
	int n;

	while (scanf("%d", &n), n){
		int sum = 0, e_sum[10] = {0};
		for (int i = 0; i < n; i++){
			int num;
			int r_sum = 0;
			for (int j = 0; j < n; j++){
				scanf("%d", &num);
				r_sum += num;
				e_sum[j] += num;
				printf("%5d", num);
			}
			sum += r_sum;
			printf("%5d\n", r_sum);
		}

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

	return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
void solve(){
  int table[200][200];

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

int main(){
  while (scanf("%d", &n), n)solve();
  return 0;
}

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

//0102
int main(){
	int n;
	while(cin >> n, n){
		int tbl[11][11]={0};

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

		for(int i=0; i<n+1; ++i){
			for(int j=0; j<n+1; ++j){
				cout.width(5);
				cout << tbl[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

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

#define int long long

signed main() {
    int n;
    while(cin>>n, n!=0) {
        int G[n+1][n+1] = {0};
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                cin >> G[i][j];
                G[i][n]+=G[i][j];
                G[n][j]+=G[i][j];
                G[n][n]+=G[i][j];
            }
        }
        for(int i=0; i<n+1; ++i) {
            for(int j=0; j<n+1; ++j) {
                if(j!=0) cout << " ";
                cout << G[i][j];
            }
            cout << setw(5) << endl;
        }
    }
    return 0;
}

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

int main(){

  int tab[11][11], n, low[11], colume[11], sum;

  while(cin >> n){
    if(n == 0) break;
    fill(low, low+11, 0);
    fill(colume, colume+11, 0);
    
    for(int i=0; i<=n; i++){
      sum = 0;
      if(i != n){
        for(int j=0; j<n; j++){
          cin >> tab[i][j];
          sum += tab[i][j];
          low[j] += tab[i][j];
        }
      }
      else{
        for(int j=0; j<n; j++){
          tab[i][j] = low[j];
          sum += low[j];
        }
      }

      tab[i][n] = sum;

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

  return 0;

}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    vector<vector<int>> vec(n + 1, vector<int>(n + 1, 0));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> vec[i][j];
        vec[i][n] += vec[i][j];
        vec[n][j] += vec[i][j];
      }
    }
    vec[n][n] = accumulate(vec[n].begin(), vec[n].end(), 0);

    for (auto &seq : vec) {
      for (auto &v : seq)
        cout << setw(5) << v;
      cout << endl;
    }
  }
}

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

int main(){
	int n;

	while(cin >> n, n){
		vector<int> vsum(n);
		int hsum = 0;
		int k;
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = 0; j < n; j++){
				cin >> k;
				printf("%5d", k);
				sum+=k;
				vsum[j]+=k;
			}
			printf("%5d\n", sum);
			hsum += sum;
		}
		vsum.push_back(hsum);

		for(int i = 0; i < n+1; i++){
			printf("%5d", vsum[i]);
		}
		cout << endl;
	}

	return 0;
}

C++: #include<stdio.h>
int d[10][10];
int t[10][10];
int n;
int i,j;
int res;

int main(){
	while(1){
	scanf("%d",&n);
	if(n==0)return 0;
	for(i=0;i<n;i++)for(j=0;j<n;j++){
		scanf("%d",&d[i][j]);
		t[i][j]=0;
	}
	for(i=0;i<n;i++){
		res=0;
		for(j=0;j<n;j++){
			res+=d[i][j];
			printf("%-5d",d[i][j]);
		}
		printf("%-5d\n",res);
	}
	for(i=0;i<n;i++){
		res=0;
		for(j=0;j<n;j++){
			res+=d[j][i];
		}
		printf("%-5d",res);
	}
	res=0;
	for(i=0;i<n;i++)for(j=0;j<n;j++){
		res+=d[i][j];
	}
	printf("%-5d\n",res);
	}
}

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

using namespace std;

int main() {
	int num;
	while(cin>>num, !cin.eof()) {
		if(num==0) break;
		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];
			}
		}
		int all_sum = 0;
		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<< setw(5)<<right<< row_sum<<endl;
			all_sum += row_sum;
		}

		for(int i=0; i<num; i++){
			cout<< setw(5)<<right<< col_num[i];
		}
		cout<< setw(5)<<right <<all_sum<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<vector<int> > num(n+1, vector<int>(n+1, 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=0; j<=n; ++j){
                cout << setw(5) << num[i][j];
            }
            cout << endl;
        }
    }
}