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 number;
    int sum = 0;
    
    while(1){
        cin >> number;
        if (number == 0){
            break;
        }
        
       
        int array[number][number];
        int lastColumn[number];
        int lastRow[number];
        int total=0;
        
        for(int i=0; i<number; i++){
            sum = 0;
            for(int j=0; j<number; j++){
                cin >> array[i][j];
                sum += array[i][j];
            }
            lastColumn[i] = sum;
        }
        
        for(int j=0; j<number; j++){
            sum = 0;
            for(int i=0; i<number; i++){
                sum += array[i][j];
            }
            lastRow[j] = sum;
            total +=sum;
        }
        
        for(int i=0; i<number; i++){
            for(int j=0; j<number; j++){
                printf("%5d", array[i][j]);
            }
            printf("%5d\n", lastColumn[i]);
        }
        
        for(int i=0; i<number; i++){
            printf("%5d", lastRow[i]);
         }
        printf("%5d\n", total);

    }
    
    return 0;
}

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

int main(){

  int n;
  while(true) {

    cin>>n;
    if(!n) break;

    vector< vector<int> > v;


    for(int i=0; i<n; i++) {
      vector<int> t;
      int k;
      for(int j=0; j<n; j++) {
	cin>>k;
	t.push_back(k);
      }
      v.push_back(t);
    }

    for(int i=0; i<n; i++) {
      int sum=0;
      for(int j=0; j<n; j++) {
	sum += v[i][j];
      }
      v[i].push_back(sum);
    }

    vector<int> o;
    for(int i=0; i<n+1; i++) {
      int sum=0;
      for(int j=0; j<v.size(); j++) {
	sum += v[j][i];
      }
      o.push_back(sum);
    }

    v.push_back(o);

    for(int i=0; i<v.size(); i++) {
      for(int j=0; j<v[i].size(); j++) {
	cout.width(5);
	cout<<v[i][j];
      }
      cout<<endl;
    }

  }

}

C++: #include <stdio.h>
int main() {int N,i,j,Map[105][105];while (1) {scanf("%d",&N);if (!N) return 0;for (i=0;i<=N;i++) Map[i][N]=Map[N][i]=0;
    for (i=0;i<N;Map[N][N]+=Map[i++][N]) for (j=0;j<N;j++) {scanf("%d",&Map[i][j]);Map[i][N]+=Map[i][j];Map[N][j]+=Map[i][j];}for (i=0;i<=N;i++,puts("")) for (j=0;j<=N;j++) printf("%5d",Map[i][j]);}}

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

int a[11][11];

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

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

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

    for (i = 0; i <= n; i++){
      printf("%5d", a[i][0]);
      for (j = 1; j <= n; j++){
        printf("%5d", a[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);
    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<iostream>
#include<cstdio>
using namespace std;
int main(){
long n,i,j,s,a[11][11];
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)
for(j=0;j<n;j++)cin>>a[i][j];
for(i=0;i<n;i++){
for(s=0,j=0;j<n;j++)s+=a[i][j];
a[i][j]=s;
}
for(j=0;j<=n;j++){
for(s=0,i=0;i<n;i++)s+=a[i][j];
a[i][j]=s;
}
for(i=0;i<=n;i++){
for(j=0;j<=n;j++)printf("%5d",a[i][j]);
printf("\n");
}
}
return 0;
}

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

int main(int argc, char *argv[]){
  int n;
  cin >> n;
  int mat[n + 1][n + 1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> mat[i][j];
    }
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int hor = 0;
    int var = 0;
    for (int j = 0; j < n; j++) {
      hor += mat[i][j];
      var += mat[j][i];
    }
    mat[i][n] = hor;
    mat[n][i] = var;
    sum += hor;
  }
  mat[n][n] = sum;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      printf("%5d ", mat[i][j]);
    }
    std::cout << std::endl;
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n;
	int ary[100][100];

while(1)
	{
		cin >> n;

		int sumx = 0;
		int sumy = 0;
		int sumxy = 0;

		if(n == 0)
		{
			break;
		}
		for(int i = 0; i < n; i++){
		//int sumx = 0;
		//int sumy = 0;
			for(int j = 0; j < n; j++)
			{
				cin >> ary[i][j];

				//sumx += ary[i][j];
			}
		}

			for(int i = 0; i < n; i++){
				sumx = 0;
				for(int j = 0; j < n; j++)
				{
					sumx += ary[i][j];
					sumxy += ary[i][j];

					cout << ary[i][j] << " ";
				}
				cout << sumx << endl;
			}

			for(int i = 0; i < n; i++){
				sumy = 0;
				for(int j = 0; j < n; j++)
			{
					sumy += ary[j][i];
				}
				cout << sumy << " ";
			}
			cout << sumxy  << endl;
	}
}

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

using namespace std;

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}
		vector<vector<int>> v(n, vector<int>(n));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> v[i][j];
			}
		}
		// vertical sum
		vector<int> vert(n);
		for (int i = 0; i < n; i++) {
			vert[i] = 0;
			for (int j = 0; j < n; j++) {
				vert[i] += v[i][j];
			}
		}
		// horizon sum
		vector<int> hori(n);
		for (int i = 0; i < n; i++) {
			hori[i] = 0;
			for (int j = 0; j < n; j++) {
				hori[i] += v[j][i];
			}
		}
		// all sum
		int sum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				sum += v[i][j];
			}
		}

		for (int i = 0; i < n; i++) {
			cout << setw(5) << right << v[i][0];
			for (int j = 1; j < n; j++) {
				cout << setw(5) << right << v[i][j];
			}
			cout << setw(5) << right << vert[i] << endl;
		}
		cout << setw(5) << right << hori[0];
		for (int i = 1; i < n; i++) {
			cout << setw(5) << right << hori[i];
		}
		cout << setw(5) << right << sum << endl;
	}
}