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

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

        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
               table[i][n] += table[i][j];
            }
        }
        
        for(int j=0; j<=n; j++){
            for(int i=0; i<n; i++){
                table[n][j] += table[i][j];
            }
        }
        
        for(int i=0; i<=n; i++){
            for(int j=0; j<=n; j++){
                cout<<table[i][j]<<" ";
            }
            cout<<endl;
        }
    }
    
    return 0;
}

C++: #include <cstdio>
#include <cstring>

#define repeat(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int table[11][11];

int main() {
  for (;;) {
    int n;
    scanf("%i", &n);
    if (!n) return 0;
    memset(table, 0, sizeof table);
    repeat(i, n) {
      repeat(j, n) {
        scanf("%i", &table[i][j]);
        table[i][n] += table[i][j];
        table[n][j] += table[i][j];
        printf("%5i", table[i][j]);
      }
      printf("%5i\n", table[i][n]);
    }
    repeat(i, n)
      table[n][n] += table[n][i];
    repeat (i, n+1)
      printf("%5i", table[n][i]);
    puts("");
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int graph[128][128];
	int num;
	
	while(cin >> num)
	{
		if(!num) break;
		int count = 0;
		int all = 0, las[128];
		for(int i = 0; i < 128; i++)
			las[i] = 0;

		for(int i = 0; i < num; i++)
		{
			for(int j = 0; j < num; j++)
			{
				cin >> graph[i][j];
				count += graph[i][j];
				las[j]  += graph[i][j];
				all += graph[i][j];
				if(j == num - 1) 
				{
					graph[i][j+1] = count;
					count = 0;
				}
				if(i == num - 1)
				{
					graph[i+1][j] = las[j];
				}
				if(i == num - 1 && j == num - 1)
				{
					graph[i+1][j+1] = all;
				}
			}
		}

		for(int i = 0; i < num + 1; i++)
		{
			for(int j = 0; j < num + 1; j++)
			{
				printf("%5d", graph[i][j]);
				if(j != num)
					printf(" ");
			}
			puts("");
		}

	}
}

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

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) {
                printf("%5d", G[i][j]);
            }
            cout << endl;
        }
    }
    return 0;
}

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

int main(void) {

  int size;
  int matrix[10][10];

  int sum_row,sum_column,sum;
  char line[200];
  char* p;

  int i,j;
  char c;

  
  while(1) {

    scanf("%d",&size);
    c=getchar();

    if(size==0) break;

    for(i=0;i<size;i++) {

      fgets(line,sizeof(line),stdin);
      line[strlen(line)-1]='\0';

      p=strtok(line," ");
      matrix[i][0]=atoi(p);

      for(j=1;j<size;j++) {
	p=strtok(NULL," ");
	matrix[i][j]=atoi(p);
      }

    }

    for(i=0;i<size;i++) {
     
      sum_row=0;

      for(j=0;j<size;j++) {

	printf("%5d",matrix[i][j]);

	sum_row+=matrix[i][j];

      }

      printf("%5d\n",sum_row);
    }

    sum=0;

    for(j=0;j<size;j++) {

      sum_column=0;

      for(i=0;i<size;i++) {

	sum_column+=matrix[i][j];

      }

      sum+=sum_column;

      printf("%5d",sum_column);
    }

    printf("%5d\n",sum);

  }

  return 0;

}

C++: #include<iostream>
#include<iomanip>
using namespace std;
int main(void)
{
    int n,A=0,ober[10][10],side[10],lon=0;
    while(1){
        for(int i=0;i<12;i++)side[i]=0;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cin>>ober[i][j];
                side[j]+=ober[i][j];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<setw(5)<<ober[i][j]<<" ";
                A+=ober[i][j];
            }
            cout<<setw(5)<<A<<"\n";
            lon+=A;
            A=0;
        }
        for(int i=0;i<n;i++)cout<<setw(5)<<side[i]<<" ";
        cout<<setw(5)<<lon<<"\n";
        lon=0;
    }
    cout<<"\n";
}

C++: #include<iostream>
#include<vector>
int main()
{
	while (1) {
		int sum = 0;
		int num;
		std::cin >> num;
		if (num == 0)break;
		std::vector<std::vector<int>>vec(num + 1, std::vector<int>(num + 1));
		for (int i = 0; i < num; ++i) {
			for (int j = 0; j < num; ++j) {
				std::cin >> vec[i][j];
			}
		}
		for (int i = 0; i < num; ++i) {
			for (int j = 0; j < num; ++j) {
				vec[num][i] += vec[j][i];
				sum += vec[j][i];
				vec[i][num] += vec[i][j];
			}
		}
		vec[num][num] = sum;
		for (int i = 0; i < num + 1; ++i) {
			for (int j = 0; j < num + 1; ++j) {
				if (j == num)std::cout << vec[i][j] << std::endl;
				else std::cout << vec[i][j] << " ";
			}
		}
	}
	return 0;
}

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

int main(){
    int n = 0;
    while (1){
	cin >> n;
	if (!n) break;
	vector<vector<int> > matrix(n+1, vector<int>(n+1));
	int input;
	for (int a = 0; a < n; a++){
	    matrix[a][n] = 0;
	    for (int b = 0; b < n; b++){
		cin >> matrix[a][b];
		matrix[a][n] += matrix[a][b];
	    }
	}
	for (int a = 0; a < n; a++){
	    for (int b = 0; b < n; b++){
		matrix[n][b] += matrix[a][b];
	    }
	}
	for (int b = 0; b < n; b++)
	    matrix[n][n] += matrix[n][b];

	for (int a = 0; a < n+1; a++){
	    for (int b = 0; b < n+1; b++)
		cout << setw(5) << right << matrix[a][b] << " ";
	    cout << '\n';
	}
    }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)

int nums[12][12];
int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0){break;}
        memset(nums,0,sizeof(nums));
        rep(j,n)rep(i,n)
        {
            cin>>nums[i][j];
            nums[i][n] += nums[i][j];
            nums[n][j] += nums[i][j];
        }
        rep(i,n){nums[n][n] += nums[i][n];}
        
        rep(j,n+1)
        {
            rep(i,n+1)
            {
                printf("%5d",nums[i][j]);
            }
            cout << endl;
        }

    }
    return 0;
}