Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}

		a := make([][]int, n+1)
		for i := 0; i < n; i++ {
			sum := 0
			stdin.Scan()
			a[i] = make([]int, n+1)
			str := strings.Split(stdin.Text(), " ")
			for j := 0; j < n; j++ {
				a[i][j], _ = strconv.Atoi(str[j])
				sum += a[i][j]
				fmt.Printf("%5d", a[i][j])
			}
			a[i][n] = sum
			fmt.Printf("%5d\n", a[i][n])
		}
		a[n] = make([]int, n+1)
		for i := 0; i <= n; i++ {
			sum := 0
			for j := 0; j < n; j++ {
				sum += a[j][i]
			}
			a[n][i] = sum
			fmt.Printf("%5d", a[n][i])
		}
		fmt.Println()
	}
}

C++: #include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

int n;

int main(){
	while(1){
		cin>>n;
		if(!n) break;
		vvi ans(n+1,vi(n+1));
		for(int i=0;i<n;i++){
			int tmp=0;
			for(int j=0;j<n;j++){
				cin>>ans[i][j];
				tmp+=ans[i][j];
			}
			ans[i][n]=tmp;
		}
		for(int i=0;i<=n;i++){
			int tmp=0;
			for(int j=0;j<n;j++){
				tmp+=ans[j][i];
			}
			ans[n][i]=tmp;
		}
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				cout.width(5);
				cout<<ans[i][j];
			}
			cout<<endl;
		}
	}
}

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

C++: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int a[15][15];
int main() {
	int n;
	while (cin >> n, n) {
		rep(i, n) {
			rep(j, n) {
				scanf("%d", &a[i][j]);
			}
		}
		rep(i, n) {
			int cnt = 0;
			rep(j, n)cnt += a[i][j];
			a[i][n] = cnt;
		}
		rep(i, n) {
			int cnt = 0;
			rep(j, n)cnt += a[j][i];
			a[n][i] = cnt;
		}
		a[n][n] = 0;
		rep(i, n)a[n][n] += a[i][n];
		rep(i, n + 1) {
			rep(j, n + 1) {
				printf("%5d", a[i][j]);
				if (j == n)printf("\n");
			}
		}
	}
	return 0;
}

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

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    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<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=1;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;a=0;
}
}


}

return 0;
}

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

using namespace std;

int main() {
	int num;
	while(cin>>num, !cin.eof()) {
		int table[num][num];
		int col_num[num];

		for(int i=0; i<num; i++){
			for(int j=0; j<num; j++){
				cin>>table[i][j];
			}
		}
		for(int i=0; i<num; i++){
			int row_sum = 0;
			for(int j=0; j<num; j++){
				cout<< setw(5)<<right <<table[i][j]<<" ";
				row_sum+=table[i][j];
				col_num[j] += table[i][j];
			}
			cout<<row_sum<<endl;
		}
		for(int i=0; i<num; i++){
			cout<< setw(5)<<right<< col_num[num];
		}
	}
	return 0;
}

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

int main(){
	int n;
	while (cin >> n) {
		if (n == 0) { break; }
		int x, y, a[15][15] = {};
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j <= n; j++) {
				if (j == n) {
					a[i][n] = sum;
					continue;
				}
				cin >> a[i][j];
				sum += a[i][j];
			}
		}
		for (int i = 0; i<n; i++) {
			for (int j = 0; j <= n; j++) {
				a[n][j] += a[i][j];
			}
		}
		for (int i = 0; i<=n; i++) {
			for (int j = 0; j <= n; j++) {
				int k;
				if (a[i][j] != 0) {
					k = log10(a[i][j]);
					k = 4 - k;
				}
				else{
					k = 4;
				}
				for(int z = 0; z < k; z++){
					cout << " ";
				}
				cout << a[i][j];
			}

			cout << endl;
		}
	}
	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 i, int j, int ei, int ej) {
  int sum = 0;
  for(; i < ei; ++i) {
    for(; 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;
}

C++: #include <cstdio>

int main(){
  int n;
  
  while(1){
    scanf("%d", &n);
    if(!n) break;
    
    int table[11][11] = {0};
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	scanf("%d", &table[i][j]);
      }
    }
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	table[i][n] += table[j][i];
	table[n][i] += table[i][j];
      }
    }
    
    for(int i=0; i<n; i++)
      table[n][n] += table[n][i];
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++)
	printf("%5d", table[i][j]);
      putchar('\n');
    }
  }
    
  return 0;
}