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 <cstring>
using namespace std;

int main(void){
	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[n][j] += t[i][j];
				t[i][n] += t[i][j];
			}
		}

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

	return 0;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int n;
int t[11][11];
int main(){
  while(cin>>n){
    if(n==0)break;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
    cin>>t[i][j];
      }
    }
    for(int j=0;j<n;j++){
      t[n][j]=0;
      for(int i=0;i<n;i++){
    t[n][j]+=t[i][j];
      }
    }
    for(int i=0;i<=n;i++){
      t[i][n]=0;
      for(int j=0;j<n;j++){
    t[i][n]+=t[i][j];
      }
    }
 
    for(int i=0;i<=n;i++){
       
      for(int j=0;j<=n;j++){
 
    printf("%5d",t[i][j]);
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>

int main(void){

    int n;
    int i,j;
    scanf("%d",&n);
    if(n==0)exit(0);
    int a[11][11]={{0}};
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            scanf("%d",&a[i][j]);
            }
        }
    for(i=0;i<n;i++){
        a[n][i]=a[0][i]+a[1][i]+a[2][i]+a[3][i]+a[4][i]+a[5][i]+a[6][i]+a[7][i]+a[8][i]+a[9][i];
    }
    for(j=0;j<n+1;j++){
        a[j][n]=a[j][0]+a[j][1]+a[j][2]+a[j][3]+a[j][4]+a[j][5]+a[j][6]+a[j][7]+a[j][8]+a[j][9];
    }
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            printf("%5d",a[i][j]);
            }
            printf("\n");
        }

return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int n, tbl[15][15];
	
	while (cin >> n, n) {
		for_(i,0,n) for_(j,0,n) cin >> tbl[i][j];
		
		tbl[n][n] = 0;
		for_(i,0,n) {
			int sumi = 0, sumj = 0;
			
			for_(j,0,n) {
				sumi += tbl[i][j];
				sumj += tbl[j][i];
			}
			
			tbl[i][n] = sumi;
			tbl[n][i] = sumj;
			tbl[n][n] += sumi;
		}
		
		for_(i,0,n+1) {
			for_(j,0,n+1) printf("%5d", tbl[i][j]);
			cout << endl;
		}
	}
}

C++: #include <stdio.h>

int main(void)
{
	int a[11][11];
	int n, i, j;

	scanf("%d", &n);
	while (n != 0)
	{
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				scanf("%d", &a[i][j]);

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

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

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

	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++){
      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()
{
  while (true)
  {
    int n;
    cin >> n;
    if ( n == 0 ) break;
    int **array = new int*[n+1];
    for (int i=0; i<n+1; i++)
    {
      array[i] = new int[n+1];
    }

    for (int i=0; i<n+1; i++)
    {
      for (int j=0; j<n+1; j++)
      {
        array[i][j] = 0;
      }
    }

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

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

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

    for (int i=0; i<n+1; i++)
    {
      delete[] array[i];
    }
    delete[] array;
  }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,glap[12][12]={0},all;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>glap[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            glap[i][n]+=glap[i][j];
            glap[n][i]+=glap[j][i];
        }
    }
    for(int i=0;i<n;i++){
        glap[n][n]+=glap[n][i];
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            printf("%5d",glap[i][j]);
        }
        cout<<endl;
    }
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <climits>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    while (cin >> n && n) {
        vector<vector<int>> mat(n+1, vector<int>(n+1, 0));
        for (int i=0; i<n; ++i) {
            for (int j=0; j<n; ++j) {
                cin >> mat[i][j];
                mat[n][j] += mat[i][j];
                mat[i][n] += mat[i][j];
                mat[n][n] += mat[i][j];
            }
        }
        for (int i=0; i<n+1; ++i) {
            for (int j=0; j<n+1; ++j) {
                cout << setw(5) << mat[i][j];
            }
            cout << endl;
        }
    }

    return 0;
}

C++: #include <stdio.h>

int main(void){
	int matrix[11][11],i,j,dataset;
	while(scanf("%d",&dataset)){

		if(dataset==0)break;

		//init add total norm
		for(i=0;i<dataset+1;i++){
			matrix[dataset][i]=0;
			matrix[i][dataset]=0;
		}

		//input and calc
		for(i=0;i<dataset;i++){
			for(j=0;j<dataset;j++){
				scanf("%d",&matrix[i][j]);
				matrix[i][dataset]+=matrix[i][j];
			}
		}

		//calc
		for(j=0;j<dataset+1;j++){
			for(i=0;i<dataset;i++){
				matrix[dataset][j]+=matrix[i][j];
			}
		}

		//output
                for(i=0;i<dataset+1;i++){
                        for(j=0;j<dataset+1;j++){
                                printf("%5d",matrix[i][j]);
                        }
			printf("\n");
                }
	}
}