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 <iomanip>
using namespace std;
int main(){
	while(1){
	int n; cin >> n ;
	if(!n) break;
	int num[10][10];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++) cin >> num[i][j];
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=0;j<n;j++){
			sum+=num[i][j];
			// if(j) cout << ' ' ;
			cout.width(5);
			cout << num[i][j] ;
		};
		cout.width(5);
	cout << sum << '\n' ;
	};
	int* sum=new int[n]; int nsum=0;
	for(int i=0;i<n;i++){
		sum[i]=0;
		// if(i) cout << ' ' ;
		for(int j=0;j<n;j++) sum[i]+=num[j][i];
		cout.width(5);
		cout << sum[i] ;
		nsum+=sum[i];
	};
	cout.width(5);
	cout << nsum << '\n' ;
	};
}

C++: #include <stdio.h>

int main(void)
{
	int n, j, i;
	int mat[15][15];
	
	while(1){
		scanf("%d", &n);
		
		if (n == 0) break;
		
		
		for (i = 0; i <= 14; i++){
			for (j = 0; j <= 14; j++){
				mat[i][j] = 0;
			}
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				scanf("%d", &mat[i][j]);
				mat[i][n] += mat[i][j];
			}
		}
		
		for (i = 0; i <= n; i++){
			for (j = 0; j < n; j++){
				mat[n][i] += mat[i][j];
			}
		}
		
		for (i = 0; i <= n; i++){
			for (j = 0; j <= n; j++){
				printf("%5d", mat[i][j]);
			}
			puts("");
		}
	}
	return (0);
}

C++: #include <iostream>
#include <iomanip>
using namespace std;
int main()
{
	int n, t[11][11], i, j, s;
	while (cin >> n && n)
	{
		for (i = 0; i < n; i++)
		{
			s = 0;
			for (j = 0; j < n; j++)
			{
				cin >> t[i][j];
				s += t[i][j];
			}
			t[i][n] = s;
		}
		for (i = 0; i < n; i++)
		{
			s = 0;
			for (j = 0; j < n; j++)
				s += t[j][i];
			t[n][i] = s;
		}
		s = 0;
		for (i = 0; i < n; i++)
		{
			s += t[i][n];
		}
		t[n][n] = s;
		cout << right;
		for (i = 0; i <= n; i++)
		{
			for (j = 0; j <= n; j++)
			{
				cout << setw(5) << t[i][j];
			}
			cout << endl;
		}
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int dp[15][15];
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>dp[i][j];
	int x=0;
	for(int i=0;i<n;i++){
		int h=0;
		for(int j=0;j<n;j++)
			h+=dp[i][j];
		dp[i][n]=h;
		x+=h;
	}
	for(int i=0;i<n;i++){
		int h=0;
		for(int j=0;j<n;j++)
			h+=dp[j][i];
		dp[n][i]=h;
	}
	dp[n][n]=x;
	for(int i=0;i<=n;i++){
		for(int j=0;j<n;j++)
			cout<<dp[i][j]<<" ";
		cout<<dp[i][n]<<endl;
	}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main() {
    for (;;) {
    int n;
    cin >> n;
    if (n == 0) return 0;

    int matrix[n+1][n+1];

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

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

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

    matrix[n][n] = 0;
    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++) {
            cout.width(5);
            if (j == n) 
                cout << matrix[i][j];
            else 
                cout << matrix[i][j] << ' ';
        }
        cout << endl;
    }
    }

    return 0;
}

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

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int table[11][11] = {};
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> table[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += table[i][j];
            }
            table[i][n] = sum;
        }
        for (int i = 0; i <= n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += table[j][i];
            }
            table[n][i] = sum;
        }
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                printf("%5d",table[i][j]);
            }
            printf("\n");
        }
    }
}

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

int main(){

  int tab[11][11], n, low[11], colume[11], sum;

  while(cin >> n){
    if(n == 0) break;
    fill(low, low+11, 0);
    fill(colume, colume+11, 0);
    
    for(int i=0; i<=n; i++){
      sum = 0;
      if(i != n){
        for(int j=0; j<n; j++){
          cin >> tab[i][j];
          sum += tab[i][j];
          low[j] += tab[i][j];
        }
      }
      else{
        for(int j=0; j<n; j++){
          tab[i][j] = low[j];
          sum += low[j];
        }
      }

      tab[i][n] = sum;

    }
    
    for(int i=0; i<=n; i++){
      for(int j=0; j<=n; j++){
        printf("%5d", tab[i][j]);
        if(j != n) cout << " ";
      }
      cout << endl;
    }
    
  }

  return 0;

}

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

int main(){
int N,num[11][11]={},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<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;

int main(){
int N,num[11][11]={},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++)
{
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<=10;i++){
for(int j=0;j<=10;j++){
num[i][j]=0;
}
}


}

return 0;
}