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++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>

#define int64 long long int
using namespace std;

int main()
{
	int n, sum;
	int m[11][11];
	while(cin >> n){
		if(n == 0) break;
		for(int i=0; i<n; i++){
			sum = 0;
			for(int j=0; j<n; j++){
				cin >> m[i][j];
				sum += m[i][j];
				printf("%5d", m[i][j]);
			}
			printf("%5d\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;
			printf("%5d", m[n][i]);
		}
		sum = 0;
		for(int i=0; i<n; i++) sum += m[n][i];
		printf("%5d\n", sum);
	}
	return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;



int main(){

	int n,tmp,row_sum,col_sum[11];

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i=0; i < 11; i++)col_sum[i] = 0;

		for(int i=0; i < n; i++){
			row_sum = 0;
			for(int k=0; k < n; k++){
				scanf("%d",&tmp);
				printf("%5d",tmp);
				row_sum += tmp;
				col_sum[k] += tmp;
			}
			printf("%5d\n",row_sum);
			col_sum[n] += row_sum;
		}
		for(int i=0; i <= n; i++)printf("%5d",col_sum[i]);
		printf("\n");
	}

    return 0;
}

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

using namespace std;

int main()
{
    int n;
    
    while (true) {
        cin >> n;
        if (!n) {
            break;
        }
        vector<vector<int> > v(n + 1, vector<int>(n + 1, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[i][n] += v[i][j];
            }
            v[n][n] += v[i][n];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[n][i] += v[j][i];
            }
            v[n][n] += v[n][i];
        }
        for (int i = 0; i < n + 1; i++) {
            for (int j = 0; j < n + 1; j++) {
                if (j > 0) {
                    cout << ' ';
                }
                cout << setw(5) << v[i][j];
            }
            cout << '\n';
        }
    }
}

C++: 
#include <iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(){
    int a[10][10],n,i,j,tate[10]={0},yoko[10]={0},sum=0;
    while(cin>>n){
        if(n==0)break;
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                cin>>a[i][j];
                sum+=a[i][j];
                yoko[i]+=a[i][j];
                tate[j]+=a[i][j];
            }
        }
        for(i=0;i<n;i++){
            for(j=0;j<=n;j++){
                if(j==n)printf("%5d\n",yoko[i]);
                else printf("%5d",a[i][j]);
            }
        }
        for(j=0;j<=n;j++){
            if(j!=n)printf("%5d",tate[j]);
            else if(j==n)printf("%5d\n",sum);
        }
    }
     return 0;
}

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

int t[12][12];

int main(){
  int n;

  while(cin >> n, n){
    //ツ配ツ療アツづー0ツづ?渉可甘コツ可サツつオツづ?つィツつュ
    memset(t, 0, sizeof(t));

    //ツ禿シツ療債つキツづゥツづつつ「ツづ?づ? ツ債?計ツづ可堕ォツつオツつアツづ敖づ?行ツつ、
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        cin >> t[i][j];

        t[i][n] += t[i][j];
        t[n][j] += t[i][j];
        t[n][n] += t[i][j];
      }
    }

    //ツ出ツ療?
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
        printf("%5d", t[i][j]);
      }
      cout << endl;
    }
  }
}

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

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

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,data[11][11];
  while(1){
    for(int i=0;i<11;i++){
      for(int j=0;j<11;j++){
	data[i][j]=0;
      }
    }
    cin>>n;
    if(n==0){break;}
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>data[i][j];
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	data[i][n]+=data[i][j];
	data[n][i]+=data[j][i];
	data[n][n]+=data[i][j];
      }
    }
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	printf("%5d",data[i][j]);
      }
       cout<<endl;
    }
  }
  return 0;
}

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

using namespace std;

int main(){
	int n[127], tn=0,ni=0,all = 0, i = 0;
	int data[512][256];
	int tdata[256] = { 0 };
	
		//input
	while (1){
		cin >> n[ni];
		if (n[ni] == 0)break;
		tn += n[ni];
		ni++;

		for (; i < tn; i++){
			for (int j = 0; j < n[ni]; j++){
				cin >> data[i][j];
			}
		}
	}
	

	//output
	for (int k = 0; k < ni; k++){
		for (int i = 0; i < tn; i++, all = 0){
			for (int j = 0; j < n[k]; j++){
				printf(" %5d", data[i][j]);
				all += data[i][j];
				tdata[j] += data[i][j];
			}
			printf(" %5d\n", all);
		}

		all = 0;
		for (int i = 0; i < n[k]; i++){
			printf(" %5d", tdata[i]);
			all += tdata[i];
		}
		printf(" %5d\n", all);
	}
	return 0;
}

C++: #include<iostream>

int main(){
	int n;
	while(std::cin>>n,n){
		int data[5][5];
		memset(data,0,sizeof(data));
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				std::cin>>data[i][j];
				data[i][4]+=data[i][j];
				data[4][j]+=data[i][j];
				data[4][4]+=data[i][j];
			}
		}
		for(int i=0;i<5;i++){
			for(int j=0;j<5;j++){
				std::cout<<data[i][j]<<" ";
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

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++) {
				if(x == nn)
					printf("%5d", matrix[y][x]);
				else
					printf("%5d ", matrix[y][x]);
			}
			printf("\n");
		}
	}

	return 0;
}