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

int main(){
  int n;
  while(cin>>n){
    int a[11][11],b[10]={},c[10]={},d=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	cin>>a[i][j];
    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++){
	b[i]+=a[i][j];
	c[i]+=a[j][i];
      }
    for(int i=0;i<n;i++)
      d+=b[i];
    for(int i=0;i<n+1;i++){
      a[i][n]=b[i];
      a[n][i]=c[i];
      a[n][n]=d;
    }
    for(int i=0;i<n+1;i++){
      for(int j=0;j<n+1;j++)
	printf("%5d",a[i][j]);
      cout<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(true){
  cin>>n;
  if(!n)break;
  int table[n+1][n+1];
  for(int y=0;y<n;y++){
    int s = 0;
    for(int x=0;x<n;x++){
      cin>>table[x][y];
      s+=table[x][y];
    }
    table[n][y] = s;
  }
  for(int x=0;x<n+1;x++){
    int s = 0;
    for(int y=0;y<n;y++){
      s+=table[x][y];
    }
    table[x][n] = s;
  }
  for(int y=0;y<n+1;y++){
    for(int x=0;x<n;x++){
      printf("% 4d ",table[x][y]);
    }
    printf("% 4d\n",table[n][y]);
  }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n!=0){
    int hyou[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>hyou[i][j];
      }
    }
    int hyoup[n+1][n+1]={0};
    hyoup[0][n]=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	hyoup[i][j]=hyou[i][j];
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	hyoup[i][n]+=hyou[i][j];
	hyoup[n][i]+=hyou[j][i];
      }
    }
    for(int i=0;i<n;i++)
      hyoup[n][n]+=hyoup[n][i];
    for(int i=0;i<n+1;i++){
      for(int j=0;j<n+1;j++){
	printf("%5d",hyoup[i][j]);
      }
      cout<<endl;
    }
  }
  return 0;
}

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

int main()
{
  int map[10][10];
  int n;

  while (std::cin >> n) {
    if (n == 0) break;

    for (int y = 0; y < n; ++y) {
      map[y][n] = 0;
      for (int x = 0; x < n; ++x) {
        std::cin >> map[y][x];
        map[y][n] += map[y][x];
      }
    }

    for (int x = 0; x <= n; ++x) {
      map[n][x] = 0;
      for (int y = 0; y < n; ++y) {
        map[n][x] += map[y][x];
      }
    }
    
    for (int y = 0; y <= n; ++y) {
      for (int x = 0; x <= n; ++x) {
        printf("%5d", map[y][x]);
      }
      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("%5d ",answer[f1][f2]);
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n,i,j,k;

  while(1){
    cin>>n;
    if(n==0)break;
    int matrix[15][15]={};

    rep(i,n){
      int sum=0;
      rep(j,n){
	scanf("%d",&matrix[i][j]);
	sum+=matrix[i][j];
      }
      matrix[i][j]=sum;
    }
    rep(j,n+1){
      int sum=0;
      rep(i,n)
	sum+=matrix[i][j];
      matrix[i][j]=sum;
    }

    rep(i,n+1){
      rep(j,n+1)
	printf("%5d",matrix[i][j]);
      puts("");
    }
  }
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n;
	short matrix[11][11];

	while(cin >> n, n)
	{
		for(int i=0; i < n; i++) matrix[n][i] = matrix[i][n] = 0;
		matrix[n][n] = 0;
		for(int y=0; y < n; y++) {
			for(int x=0; x < n; x++) {
				cin >> matrix[y][x];
				matrix[n][x] += matrix[y][x];
				matrix[y][n] += matrix[y][x];
				matrix[n][n] += matrix[y][x];
			}
		}
		int nn = n + 1;
		for(int y=0; y < nn; y++) {
			for(int x=0; x < nn; x++) {
				printf("%5d ", matrix[y][x]);
			}
			printf("\n");
		}
	}

	return 0;
}

C++: #define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 11
#define HO 6
int main(void)
{
	int n;
	while (1) {
		scanf_s("%d", &n);
		if (n == 0) break;
		int date[MAX][MAX] = { 0 };
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				scanf_s("%d", &date[i][j]);
				date[i][n] += date[i][j];
				date[n][j] += date[i][j];
				date[n][n] += date[i][j];
			}
		}
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				printf("%5d", date[i][j]);
			}
			printf("\n");
		}
		
	}
}

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

int main(){
	int data_size;
	cin >> data_size;
	while (data_size){
		vector<vector<int>> data;
		vector<vector<int>> data_digit;
		data.resize((data_size + 1)*(data_size + 1));
		data_digit.resize((data_size + 1) * (data_size + 1));
		for (int i = 0; i < data_size; i++){
			data[i].resize(data_size + 1);
			data_digit[i].resize(data_size + 1);
			for (int j = 0; j < data_size; j++){
				cin >> data[i][j];
				int tmp = data[i][j];
				data_digit[i][j] = 0;
				while (tmp){
					tmp /= 10;
					data_digit[i][j]++;
				}
			}
		}
		data[data_size].resize(data_size + 1);
		data_digit[data_size].resize(data_size + 1);
		for (int i = 0; i < data_size; i++){
			int sum = 0;
			for (int j = 0; j < data_size; j++){
				sum += data[i][j];
			}
			data[i][data_size] = sum;
			int tmp = sum;
			data_digit[i][data_size] = 0;
			while (tmp){
				tmp /= 10;
				data_digit[i][data_size]++;
			}

		}
		for (int i = 0; i < data_size + 1; i++){
			int sum = 0;
			for (int j = 0; j < data_size; j++){
				sum += data[j][i];
			}
			data[data_size][i] = sum;
			int tmp = sum;
			data_digit[data_size][i] = 0;
			while (tmp){
				tmp /= 10;
				data_digit[data_size][i]++;
			}
		}

		for (int i = 0; i < data_size + 1; i++){
			for (int j = 0; j < data_size + 1; j++){
				for (int k = data_digit[i][j]; k < 5; k++){
					cout << " ";
				}
				cout << data[i][j];
			}
			if (i!=data_size)
			cout << "\n";
		}
		
		cin >> data_size;
		if (data_size != 0){
			cout << "\n";
		}
	}
	return 0;
}

C++: #include <stdio.h>
int main(){
	int n;
	while(1){
	    int l,r;
		int a[11][11];
		scanf("%d",&n);
		if(!n) break;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++) scanf("%d",&a[i][j]);
		}
		for(int i=0;i<n+1;i++){
			l=r=0;
			for(int j=0;j<n;j++){
				l+=a[i][j];
				r+=a[j][i];
			}
			a[i][n]=l;
			a[n][i]=r;
		}
		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;
}