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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<vint> v(n + 1, vint(n + 1));

		rep(i, n) rep(j, n)
			cin >> v[i][j];

		int sum = 0;
		rep(i, n) 
		{
			rep(j, n)
			{
				v[i][n] += v[i][j];
				v[n][i] += v[j][i];
			}
			sum += v[i][n];
		}
		v[n][n] = sum;

		rep(i, n+1) 
		{
			rep(j, n+1)
			{
				rep(k, 4 - log10((float)v[i][j]))
					cout << " ";
				cout << v[i][j];
			}
			cout << endl;
		}
	}
}

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

int main(){
	int num[12][12]={};
	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 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<<" ";}
*/
printf("%5d",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 <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,c;
  while(cin>>n,n){
    int a[n+1][n+1];
    rep(i,n){c=0;rep(j,n){
        cin>>a[i][j];
        c+=a[i][j];
      }
      a[i][n]=c;
    }
    rep(j,n+1){c=0;rep(i,n){
      c+=a[i][j];
    }
    a[n][j]=c;
  }
  rep(i,n+1){rep(j,n+1){cout<<a[i][j];}cout<<endl;}
  }
}

C++: #include<iostream>
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++){
	cout<<data[i][j];
	if(j<n){
	cout<<" ";
	}
      }
      cout<<endl;
    }
  }
  return 0;
}

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

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}
		vector<int> col_sum(n + 1);
		for (int i = 0;i != n + 1;++i) {
			col_sum[i] = 0;
		}
		for (int i = 0;i != n;++i) {
			int row_sum = 0;
			for (int j = 0;j != n;++j) {
				int num;
				cin >> num;
				cout << setw(5) << num;
				col_sum[j] += num;
				row_sum += num;
			}
			cout << setw(5) << row_sum << endl;
			col_sum[n] += row_sum;
		}
		for (int i = 0;i != n + 1;++i) {
			cout << setw(5) << col_sum[i];
		}
		cout << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int table[11][11];

int main(){
    int n;
    while(cin >> n, n){
    rep(i, n)rep(j, n) cin >> table[i][j];
    rep(i, n){
        int total =0;
        rep(j, n) total += table[i][j];
        table[i][n] = total;
    }
    rep(i, n+1){
        int total =0;
        rep(j, n) total += table[j][i];
        table[n][i] = total;
    }

    rep(i, n+1){
        rep(j, n+1) printf("%5d", table[i][j]);
        cout << endl;
    }
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){

  int n;

  while(cin >> n,n){

    int sheet[n + 1][n + 1];

    memset(sheet, 0, sizeof(sheet));

    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){

        cin >> sheet[i][j];
        printf("%5d", sheet[i][j]);
        sheet[i][n] += sheet[i][j];

      }

      printf("%5d\n", sheet[i][n]);

    }

    for(int i = 0; i < n + 1; ++i){
      for(int j = 0; j < n; ++j){

        sheet[n][i] += sheet[j][i];

      }

      printf("%5d", sheet[n][i]);

    }

    cout << endl;

  }

}

C++: #include<stdio.h>
int main(void)
{
	int ct,map[10][10],answer[11][11];
	while(1){
		scanf("%d",&ct);
		if(ct==0){
			return 0;
		}
		for(int f1=0;f1<11;f1++){
			for(int f2=0;f2<11;f2++){
				answer[f1][f2]=0;
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				scanf("%d",&map[f1][f2]);
				answer[f1][f2]=map[f1][f2];
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				answer[f1][ct]+=map[f1][f2];
				answer[ct][f1]+=map[f2][f1];
			}
		}
		for(int f1=0;f1<ct;f1++){
			answer[ct][ct]+=answer[f1][ct];
		}
		for(int f1=0;f1<ct+1;f1++){
			for(int f2=0;f2<ct+1;f2++){
				printf("%4d ",answer[f1][f2]);
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>

int main(void){

    int n;
    int i,j;
    while(scanf("%d",&n)!=EOF){
    int a[11][11]={{0}};
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            scanf("%d",&a[i][j]);
            }
        }
    for(i=0;i<n;i++){
        a[n][i]=a[0][i]+a[1][i]+a[2][i]+a[3][i]+a[4][i]+a[5][i]+a[6][i]+a[7][i]+a[8][i]+a[9][i];
    }
    for(j=0;j<n+1;j++){
        a[j][n]=a[j][0]+a[j][1]+a[j][2]+a[j][3]+a[j][4]+a[j][5]+a[j][6]+a[j][7]+a[j][8]+a[j][9];
    }
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            printf("%5d",a[i][j]);
            }
            printf("\n");
        }
    }
return 0;
}