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];

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

		rep(i, n+1) 
		{
			rep(j, n+1)
			{
				cout << v[i][j];
				if(j < n) cout << " ";
			}
			cout << endl;
		}
	}
}

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

int main() {
	int N;

	while (cin >> N && N != 0) {
		int dataset[N+1][N+1];
        for (int i = 0; i != N; ++i) {
            for (int j = 0; j != N; ++j) {
                cin >> dataset[i][j];
            }
        }

        for (int i = 0; i != N; ++i) {
            int total = 0;
            for (int j = 0; j != N; ++j) {
                total += dataset[i][j];
            }
            dataset[i][4] = total;
        }

        for (int i = 0; i != N; ++i) {
            int total = 0;
            for (int j = 0; j != N; ++j) {
                total += dataset[j][i];
            }
            dataset[4][i] = total;
        }

        int ans = 0;
        for (int i = 0; i != N; ++i) {
            ans += dataset[4][i] + dataset[i][4];      
        }
        dataset[4][4] = ans;

        for (int i = 0; i != N+1; ++i) {
            for (int j = 0; j != N+1; ++j) {
                cout << setw(5) << dataset[i][j];
            } 
            cout << endl;
        }
	}
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  int M[12][12];
  while(cin>>n,n){
    rep(i,n)rep(j,n)cin>>M[i][j];
    rep(i,n){
      int tmp=0;
      rep(j,n)tmp+=M[i][j];
      M[i][n]=tmp;
    }
    rep(i,n){
      int tmp=0;
      rep(j,n)tmp+=M[j][i];
      M[n][i]=tmp;
    }
    int tmp=0;
    rep(i,n)tmp+=M[n][i];
    M[n][n]=tmp;
    rep(i,n+1){
      rep(j,n+1){
        cout<<M[i][j];
        if(j<n+1)cout<<' ';
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	while (n != 0) {
		int a[10][10] = {}, sum_h[11] = {}, sum_v[11] = {};
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> a[i][j];
				printf("%5d",a[i][j]);
				sum_h[i] += a[i][j];
				sum_v[j] += a[i][j];
			}
			sum_v[n] += sum_h[i];
			printf("%5d\n", sum_h[i]);
		}
		for (int i = 0; i < n; i++)
			printf("%5d", sum_v[i]);
		printf("%5d\n", sum_v[n]);
		cin >> n;
	}
	return 0;
}

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

int main(){
	int n,i,j;
	while(cin >> n && n){
		int table[11][11] = {{0}};
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				cin >> table[i][j];
				table[i][n] += table[i][j];
				table[n][j] += table[i][j];
			}
			table[n][n] += table[i][n];
		}
		for(i = 0;i <= n;i++){
			for(j = 0;j <= n;j++){
				if(table[i][j] / 100 != 0) cout << "  ";
				else cout << "   ";
				cout << table[i][j];
			}
			cout << "\n";
		}
	}
	return 0;
}

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

int main(){
	
	int n,h,w;
	while(cin>>n){
		if(n!=0){
		int sw=0;
		vector< vector<int> >c(n+2,vector<int>(n+2));
		for(int i=0;i<n;i++){
				w=0;
			for(int j=0;j<n;j++){
				cin>>c[i][j];
				w+=c[i][j];
			}
			c[i][n]=w;
			sw+=w;
		}
		for(int i=0;i<n;i++){
			h=0;
			for(int j=0;j<n;j++){
			h+=c[j][i];
		}
			c[n][i]=h;
		}
		c[n][n]=sw;
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++)
			printf("%5d",c[i][j]);
			cout<<endl;
		}
		
		
	}
		else
			break;
	}
		
	
}

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

using namespace std;

int main(){
	int n,all=0;
	int data[256];
	int tdata[256] = { 0 };
	
	cin >> n;

	for (int i = 0; i < n; i++,all=0){
		for (int j = 0; j < n; j++){
			cin >> data[j];
			printf(" %d",data[j]);
			all += data[j];
			tdata[j] += data[j];
		}
		printf(" %d\n", all);
	}

	all = 0;
	for (int i = 0; i < n; i++){
		printf(" %d", tdata[i]);
		all += tdata[i];
	}
	printf(" %d\n", all);

	return 0;
}

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

int main()
{
	while (1)
	{
		int a;
		cin >> a;
		if (a == 0)break;
		vector<int>tate(a+1);
		for (int b = 0; b < a; b++) 
		{
			vector<int>yoko(a);
			int s = 0;
			for (int c = 0; c < a; c++)
			{
				int d;
				cin >> d;
				yoko[c] = d;
				s +=d;
				tate[c] += d;
			}
			for (int k : yoko) {
				cout << setw(5) << k;
			}
			tate[a] += s;
			cout << setw(5) << s <<endl;
		}
		for (int k : tate) {
			cout << setw(5) << k;
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	int n, a[10][10] = {}, sum_h[11] = {}, sum_v[11] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			cout << a[i][j] << " ";
			sum_h[i] += a[i][j];
			sum_v[j] += a[i][j];
		}
		sum_v[n] += sum_h[i];
		cout << sum_h[i] << endl;
	}
	for (int i = 0; i < n; i++)
		cout << sum_v[i] << " ";
	cout << sum_v[n] << endl;
	return 0;
}

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

int n;
int tbl[11][11];

int main()
{
	while( std::cin >> n, n )
	{
		memset( tbl, 0, sizeof( tbl ) );

		for( int i = 0; i != n; ++i )
		{
			for( int j = 0; j != n; ++j )
			{
				std::cin >> tbl[i][j];
	
				tbl[i][n] += tbl[i][j];
				tbl[n][j] += tbl[i][j];
				tbl[n][n] += tbl[i][j];
			}
		}

		for( int i = 0; i <= n; ++i )
		{
			for( int j = 0; j <= n; ++j )
				std::cout << std::setw( 5 ) << std::right << tbl[i][j];	
	
			std::cout << std::endl;
		}
	}

	return 0;
}