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(void){
        int n=0;
        while(1) {
                cin>>n;
                if(n==0) return 0;
                int a[n+1][n+1];
                int s;
                for(int i=0; i<n; i++) {
                        s=0;
                        for(int j=0; j<n; j++) {
                                a[i][j]=0;
                                cin>>a[i][j];
                                s+=a[i][j];
                        }
                        a[i][n]=s;
                }

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

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

                }
        }

        return 0;

}

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

int main(){
  int n;
  int a[10][10];
  int sum, amount;
  int i, j;

  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++){
      sum=0;
      for(j=0; j<n; j++){
        printf("%5d", a[i][j]);
        sum+=a[i][j];
      }
      printf("%5d\n", sum);
    }
    amount=0;
    for(j=0; j<n; j++){
      sum=0;
      for(i=0; i<n; i++){
        sum+=a[i][j];
      }
      printf("%5d", sum);
      amount+=sum;
    }
    printf("%5d\n", amount);
  }

  return 0;
}

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

int main(void){

    int n;
    int i,j;
    for(;;){
    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<stdio.h>
int main(void)
{
	int ct,map[10][10],answer[11][11];
	while(1){
		scanf("%d",&ct);
		if(ct==0){
			return 0;
		}
		for(int f1=0;f1<11;f1++){
			for(int f2=0;f2<11;f2++){
				answer[f1][f2]=0;
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				scanf("%d",&map[f1][f2]);
				answer[f1][f2]=map[f1][f2];
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				answer[f1][ct]+=map[f1][f2];
				answer[ct][f1]+=map[f2][f1];
			}
		}
		for(int f1=0;f1<ct;f1++){
			answer[ct][ct]+=answer[f1][ct];
		}
		for(int f1=0;f1<ct+1;f1++){
			for(int f2=0;f2<ct+1;f2++){
				printf("%6d ",answer[f1][f2]);
			}
			printf("\n");
		}
	}
	return 0;
}

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

int n;
int field[1000][1000];
int total;

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    total = 0;
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
        scanf("%d", &field[i][j]);
        total += field[i][j];
      }
    }

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

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

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

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

int main()
{
	int n;
	while(cin>>n&&n)
	{
		int a[15][15]={};
		for(int i=0;i<n;i++)
		{
			int sum=0;
			for(int j=0;j<n;j++)
			{
				cin>>a[i][j];
				sum+=a[i][j];
			}
			a[i][n]=sum;
		}
		for(int j=0;j<=n;j++)
		{
			int sum=0;
			for(int i=0;i<n;i++)
			{
				sum+=a[i][j];
			}
			a[n][j]=sum;
		}
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=n;j++)
			{
				printf("%5d",a[i][j]);
			}
			printf("\n");
		}
		
	}
	/*
	int ix,*pix;
	double dx,*pdx;
	
	scanf("%d",&ix);
	scanf("%lf",&dx);
	
	pix=&ix;
	pdx=&dx;
	
	
	
	printf("ix = %d, pix = %d\n",ix,*pix);
	printf("dx = %lf, pdx = %lf\n",dx,*pdx);
	*/
}

C++: #include <cstdio>

int main(){
	int n;
	int M[11][11];
	int sum;
	
	for(;;){
		scanf("%d", &n);
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			sum = 0;
			for(int j = 0; j < n; j++){
				scanf("%d", &M[i][j]);
				sum += M[i][j];
			}
			M[i][n] = sum;
		}
	
		for(int i = 0; i <= n; i++){
			sum = 0;
			for(int j = 0; j < n; j++){
				sum += M[j][i];
			}
			M[n][i] = sum;
		}
	
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%5d", M[i][j]);
			}
			putchar('\n');
		}
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int a[11][11] = {0};
	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]);

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

		for (j = 0; j < n; j++)
			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 <iostream>
#include <cstdio>
using namespace std;

int Matrix[11][11];

int main(void){
  int n;
  while(cin >> n && n != 0){
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> Matrix[i][j];
    int s = 0;
    for(int i = 0; i < n; i++){
      int sumt = 0, sumy = 0;
      for(int j = 0; j < n; j++){
        sumt += Matrix[i][j];
        sumy += Matrix[j][i];
      }
      Matrix[i][n] = sumt;
      Matrix[n][i] = sumy;
      s += sumt + sumy;
    }
    Matrix[n][n] = s;
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
        printf("%5d", Matrix[j][i]);
      }
      cout << endl;
    }
  }
  return 0;
}

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

using namespace std;
  
main(){
  int n;
  cin>>n;
 while(n!=0){
    int d[n+1][n+1];

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

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

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