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

int main(void){
  int n;
  int tmp;

  while(cin >> n && n){
	int colsum[n+1];

	memset(colsum, 0, sizeof(colsum));
	for(int i=0;i<n;i++){
	  int sum=0;
	  for(int j=0;j<n;j++){
		cin >> tmp;
		printf("%5d", tmp);
		sum += tmp;
		colsum[j] += tmp;
	  }
	  printf("%5d\n", sum);
	  colsum[n] += sum;
	}
	for(int i=0;i<n+1;i++){
	  if(i!=n){
		printf("%5d", colsum[i]);
	  }else{
		printf("%5d\n", colsum[i]);
	  }
	}
  }
  
}

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

#define MAX_N 10

int a[MAX_N+1][MAX_N+1];
int n;

void solve() {
    // row sum
    for (int i=0; i<n; i++) {
        a[i][n] = 0;
        for (int j=0; j<n; j++) {
            a[i][n] += a[i][j];
        }
    }
    // column sum
    for (int j=0; j<n; j++) {
        a[n][j] = 0;
        for (int i=0; i<n; i++) {
            a[n][j] += a[i][j];
        }
    }
    // total sum
    a[n][n] = 0;
    for (int i=0; i<n; i++) a[n][n] += a[i][n];

    // output
    for (int i=0; i<n+1; i++) {
        for (int j=0; j<n+1; j++) {
            std::cout << std::setw(5) << a[i][j];
        }
        std::cout << std::endl;
    }
}

int main() {
    while(std::cin >> n, n) {
        for (int i=0; i<n; i++) {
            for (int j=0; j<n; j++) {
                std::cin >> a[i][j];
            }
        }
        solve();
    }
}

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

int main()
{
	int n;

	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++){
			int num, sum = 0;
			for (int j = 0; j < n; j++){
				scanf("%d", &num);
				sum += num;
				printf("%5d", num);
			}
			printf("%5d\n", sum);
		}
	}

	return (0);
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (int i = 0; i < 100; i++)
	{
		int n,a[100][100];
		cin >> n;
		if (n == 0)
		{
			break;
		}

		for (int j = 0; j < n; j++)
		{
			for (int k = 0; k < n; k++)
			{
				cin >> a[j][k];
			}
		}
		int co = 0;
		int coo = 0;

		for (int j = 0; j < n; j++)
		{
			for (int k = 0; k < n; k++)
			{
				co += a[j][k];
			}
			a[j][n] = co;
			co = 0;
		}

		for (int k = 0; k < n + 1; k++)
		{
			for (int j = 0; j < n; j++)
			{
				coo += a[j][k];
			}
			a[n][k] = coo;
			coo = 0;
		}



		for (int j = 0; j < n + 1; j++)
		{
			for (int k = 0; k < n + 1; k++)
			{
				ostringstream p;
				string pp;
				p << a[j][k];
				pp = p.str();
				int l = 0;
				l = pp.size();
				if (l == 1)
				{
					cout << "    ";
				}
				else if (l == 2)
				{
					cout << "   ";
				}
				else if (l == 3)
				{
					cout << "  ";
				}
				else if (l == 4)
				{
					cout << " ";
				}
				cout << a[j][k];
			}
			cout << endl;
		}
	}
}

C++: #include "bits/stdc++.h"
using namespace std;

int main(){
	int n;
	while(1){
	cin>>n;
		if(n==0)break;
	vector<vector<int> > a(n+1,vector<int>(n+1));
	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++){
		int b=0;
		for(int j=0;j<n;j++){
			cout<<a[i][j]<<" ";
			b+=a[i][j];
		}
		cout<<b<<endl;
	}
	
	int d=0;
	
	for(int i=0;i<n;i++){
		int c=0;
		for(int j=0;j<n;j++){
			c+=a[j][i];
		}
		cout<<c<<" ";
		d+=c;
	}
	cout<<d<<endl;
	}
	return 0;
}

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

int main()
{
	int n;

	while (cin >> n, n)
	{
		int table[11][11] = {};

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

		for (int y = 0; y < n; y++)
		{
			for (int x = 0; x < n; x++)
			{
				table[n][y] += table[x][y];
			}
		}
		for (int x = 0; x < n; x++)
		{
			for (int y = 0; y < n; y++)
			{
				table[x][n] += table[x][y];
			}
		}
		for (int x = 0; x < n; x++)
		{
			table[n][n] += table[x][n];
		}

		for (int y = 0; y <= n; y++)
		{
			for (int x = 0; x <= n; x++)
			{
				cout << right << setw(4) << table[x][y] << ' ';
			}
			cout << endl;
		}
	}

	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++)
{
	printf("5%lf",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 <stdlib.h>
int main(){
	int n,i,j;
	while(1){
		int matrix[11][11]={0};
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&matrix[i][j]);
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				matrix[n][j] += matrix[i][j];
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<=n;j++){
				matrix[j][n] += matrix[j][i];
			}
		}
		for(i=0;i<=n;i++){
			for(j=0;j<n;j++){
				printf("%5d ",matrix[i][j]);
			}
			printf("%5d\n",matrix[i][n]);
		}
	}
	return (0);
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,hyo[11][11],n,wa[11],wa2[11],sum;
	while(1) {
		scanf("%d",&n);
		if(n==0)  break;
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) scanf("%d",&hyo[i][j]);
		}
		for(i=0;i<n;i++) {
			sum=0;
			for(j=0;j<n;j++) sum+=hyo[i][j];
			wa[i]=sum;
		}
		for(i=0;i<n;i++) {
			sum=0;
			for(j=0;j<n;j++) sum+=hyo[j][i];
			wa2[i]=sum;
		}
		for(i=0;i<n;i++) {
			printf(" ");
			for(j=0;j<n;j++) {
				if(hyo[i][j]==100) printf(" %d ",hyo[i][j]);
				if(hyo[i][j]<100 && hyo[i][j]>=10) printf("  %d ",hyo[i][j]);
			}
			printf("%d\n",wa[i]);
		}
		printf(" ");
		for(i=0;i<4;i++) {
			if(wa2[i]>=1000) printf("%d ",wa2[i]);
			if(wa2[i]>=100 && wa2[i]<1000) printf(" %d ",wa2[i]);
			else printf("   %d ",wa2[i]);
		}
		sum=0;
		for(i=0;i<4;i++) {
			sum+=wa[i];
		}
		if(sum==1000) printf("%d\n",sum);
		if(sum<1000 && sum>=10) printf("%d\n",sum);
	}
	return 0;
}

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

const int MAXN = 11;
int n;
int g[MAXN][MAXN];

int getSum(int bi, int bj, int ei, int ej) {
  int sum = 0;
  for(int i = bi; i < ei; ++i) {
    for(int j = bj; j < ej; ++j) {
      sum += g[i][j];
    }
  }
  return sum;
}

int main() {
  while(cin >> n && n) {
    for(int i = 0; i < n; ++i) {
      for(int j = 0; j < n; ++j) {
        cin >> g[i][j];
      }
    }
    for(int i = 0; i < n+1; ++i) {
      for(int j = 0; j < n+1; ++j) {
        int value = 0;
        if(i == n && j == n) {
          value = getSum(0, 0, n, n);
        } else if(i == n) {
          value = getSum(0, j, n, j+1);
        } else if(j == n) {
          value = getSum(i, 0, i+1, n);
        } else {
          value = g[i][j];
        }
        printf("%5d", value);
      }
      printf("\n");
    }
  }
  return 0;
}