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<cstdio>
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++){
	printf("%5d",data[i][j]);
	if(j<n){
	cout<<" ";
	}
      }
      cout<<endl;
    }
  }
  return 0;
}

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

int main(){

  int n,i,j;

  while(1){

    scanf("%d",&n);

    if(n==0){
      break;
    }

  int data[10][10]={0};
  int sum[10]={0};
  int sum2[10]={0};
  int sum3=0;

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&data[i][j]);
      sum[i]+=data[i][j];
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      sum2[i]+=data[j][i];
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%5d",data[i][j]);
    }
    printf("%5d\n",sum[i]);
    sum3+=sum[i];
  }

  for(i=0;i<n;i++){
    printf("%5d",sum2[i]);
  }
  printf("%5d\n",sum3);

  }

  return 0;
}

C++: #include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<deque>
using namespace std;

string convert(int x){
	stringstream buf;
	buf<<x;
	while(buf.str().size()<5){
		string tmp = buf.str();
		buf.str("");
		buf<<" "<<tmp;
	}
	return buf.str();
}

int main(){
	int n;
	cin>>n;
	stringstream buf;
	while(n!=0){
		vector< vector<int> > table;
		for(int x=0;x<n;++x){
			vector<int> tmp;
			int sum = 0;
			for(int i=0;i<n;++i){
				int j;cin>>j;
				tmp.push_back(j);
				sum +=j;
			}
			tmp.push_back(sum);
			table.push_back(tmp);	
		}
		vector<int> tmp;
		for(int x=0;x<table[0].size();++x){
			int sum = 0;
			for(int y=0;y<table.size();++y){
				sum += table[y][x];
			}
			tmp.push_back(sum);
		}
		table.push_back(tmp);

		for(int x=0;x<table.size();++x){
			for(int y=0;y<table[x].size();++y){
				buf<<convert(table[x][y]);
			}
			buf<<"\n";
		}
		cin>>n;
	}
	cout<<buf.str();
	return 0;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int n;
	
	while(cin >> n, n) {
		vvi field(n+1, vi(n+1, 0));

		REP(i, n) {
			REP(j, n) {
				cin >> field[i][j];		
			}
		}

		REP(i, n) {
			REP(j, n) {
				field[i][n] += field[i][j];
				field[n][j] += field[i][j];
				field[n][n] += field[i][j];
				printf("%5d", field[i][j]);
			}
			printf("%5d\n", field[i][n]);
		}

		REP(i, n+1) {
			printf("%5d", field[n][i]);
		}

		printf("\n");
	}

	
	return 0;
}

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

using namespace std;

int main(){
	int n[102], tn=0,ni=0,all = 0, i = 0,h=0;
	int data[1024][10];
	int tdata[10] = { 0 };
	
	//input
	while (1){
		cin >> n[ni];
		if (n[ni] == 0)break;
		tn += n[ni];

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


	//output
	for (int k = 0; k < ni; k++){
		for (int i=0; i < n[k]; i++, all = 0,h++){
			for (int j = 0; j < n[k]; j++){
				printf("%5d", data[h][j]);
				all += data[h][j];
				tdata[j] += data[h][j];
			}
			printf("%5d\n", all);
		}

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

		for (int i = 0; i < n[k]; i++){
			tdata[i] = 0;
		}
		all = 0;
	}
	return 0;
}

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

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

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		vvi a(n+1,vi(n+1));
		rep(i,n){
			rep(j,n){
				cin>>a[i][j];
				a[i][n]+=a[i][j];
				a[n][j]+=a[i][j];
			}
		}
		a[n][n]=accumulate(allof(a[n]),0);
		rep(i,a.size()){
			rep(j,a[i].size())
				cout<<setw(5)<<a[i][j];
			cout<<endl;
		}
		
	}
	
	return 0;
}