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(1){
		cin >> n;
		if(n==0) break;
		int a[n+1][n+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++) cin >> a[j][i];
			a[n][i] = 0;
			for(int j=0;j<n;j++) a[n][i] += a[j][i];
		}
		for(int i=0;i<=n;i++){
			a[i][n] = 0;
			for(int j=0;j<n;j++) a[i][n] += a[i][j];
		}
		for(int i=0;i<=n;i++){
			cout << a[0][i];
			for(int j=1;j<=n;j++) cout << " " << a[j][i];
			cout << endl;
		}
	}
}

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

int main(){
	double num[11][11]={};
	int N,x;
int a;
while(1)
{cin>>N;
if(N==0)break;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++)
{cin>>num[i][j];num[i][N]+=num[i][j];}
}
for(int i=0;i<N;i++)
num[N][N]+=num[i][N];
for(int i=0;i<N;i++)
	for(int j=0;j<N;j++)
num[N][i]+=num[j][i];

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++)
{
if(num[i][j]==0)a==4;
else	a =5-( (int)log10((double)(num[i][j]) )+ 1);
for(int k=0;k<a;k++)
{cout<<" ";}
cout<<num[i][j];}
cout<<endl;


}

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){
num[i][j]=0;
}
}


}

return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n, i, j, a[10], b, c, x;
  while (cin >> n && n > 0) {
    memset(a, 0, sizeof(a));
    c = 0;
    for (i = 0; i < n; i++) {
      b = 0;
      for (j = 0; j < n; j++) {
        scanf("%d", &x);
        printf("%5d", x);
        a[j] += x;
        b += x;
      }
      printf("%5d\n", b);
    }
    for (i = 0; i < n; i++) {
      printf("%5d", a[i]);
      c += a[i];
    }
    printf("%5d\n", c);
  }
  return 0;
}

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

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<<std::setw(5)<<std::right<<data[i][j];
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

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

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

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

using namespace std;

int main() {
	int hyou[10][10];
	int sum;
	int n;

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

		int s[10] = {0};

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

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

	return 0;


}

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 <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <typeinfo>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)

using namespace std;
typedef long long ll;



int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        int data[20][20]={};

        rep(i,n){
            rep(j,n){
                cin>>data[i][j];
            }
        }
        
        rep(i,n){
            int sum=0;
            rep(j,n)sum+=data[i][j];
            data[i][n]=sum;
        }
        
        rep(j,n+1){
            int sum=0;
            rep(i,n)sum+=data[i][j];
            data[n][j]=sum;
        }
        rep(i,n+1){
            rep(j,n+1){
                printf("%5d",data[i][j]);
            }
            cout<<endl;
        }
    }
    return 0;
 }

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

int main(int argc, char const* argv[])
{
	int n{};
	std::cin >> n;
	while (n) {
		std::vector<int> table{};
		for (int i = 0; i < n * n; i++) {
			int d;
			std::cin >> d;
			table.push_back(d);
		}
		for (int i = 0; i < n; i++) {
			auto hsum = 0;
			for (int j = 0; j < n; j++) {
				auto current = table[i * 4 + j];
				hsum += current;
				std::cout << std::setw(5) << std::right << current ;
			}
			std::cout << std::setw(5) << std::right << hsum;
			std::cout << std::endl;
		}
		int sum{};
		for (int i = 0; i < n; i++) {
			auto vsum = 0;
			for (int j = 0; j < n; j++) {
				auto current = table[j * 4 + i];
				vsum += current;
			}
			std::cout << std::setw(5) << std::right << vsum;
			sum += vsum;
		}
		std::cout << std::setw(5) << std::right << sum;
		std::cout << std::endl;
		std::cin >> n;
	}

	return 0;
}

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

int main(){
	double num[12][12]={};
	int N ;
int a=0;
while(1)
{cin>>N;
if(N==0)break;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++)
{cin>>num[i][j];num[i][N]+=num[i][j];}
}
for(int i=0;i<N;i++)
num[N][N]+=num[i][N];
for(int i=0;i<N;i++)
	for(int j=0;j<N;j++)
num[N][i]+=num[j][i];

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++)
{
if(num[i][j]==0)a==4;
else if(num[i][j]>0)a =5-( (int)log10((double)(num[i][j]) )+ 1);
else if(num[i][j]<0)a =4-( (int)log10((double)(-num[i][j]) )+ 1);
for(int k=0;k<a;k++)
{cout<<" ";}
cout<<num[i][j];}
cout<<endl;


}

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){
num[i][j]=0;
}
}


}

return 0;
}