Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}

		a := make([][]int, n+1)
		for i := 0; i < n; i++ {
			sum := 0
			stdin.Scan()
			a[i] = make([]int, n+1)
			str := strings.Split(stdin.Text(), " ")
			for j := 0; j < n; j++ {
				a[i][j], _ = strconv.Atoi(str[j])
				sum += a[i][j]
				fmt.Printf("%5d", a[i][j])
			}
			a[i][n] = sum
			fmt.Printf("%5d\n", a[i][n])
		}
		a[n] = make([]int, n+1)
		for i := 0; i <= n; i++ {
			sum := 0
			for j := 0; j < n; j++ {
				sum += a[j][i]
			}
			a[n][i] = sum
			fmt.Printf("%5d", a[n][i])
		}
		fmt.Println()
	}
}

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 << right << setw(5) << matrix[a][b];
	    cout << '\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;
}