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 <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	while (cin >> n&&n) {
		int g[15][15];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> g[i][j];
			}
		}
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += g[i][j];
			}
			g[i][n] = sum;
		}
		for (int j = 0; j < n; j++) {
			int sum = 0;
			for (int i = 0; i < n; i++) {
				sum += g[i][j];
			}
			g[n][j] = sum;
		}
		int ssum = 0;
		for (int i = 0; i < n; i++) {
			ssum += g[i][n];
		}
		g[n][n] = ssum;
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				if (g[i][j] < 10)cout << "    " << g[i][j];
				else if (g[i][j] < 100)cout << "   " << g[i][j];
				else if (g[i][j] < 1000)cout << "  " << g[i][j];
			}
			cout << endl;
		}
	}
}

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

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

C++: #include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int n;
	while(cin>>n,n){
		int data[20][20];
		rep(i,20)rep(j,20)data[i][j]=0;
		for(int i =0;i < n;i++){
			for(int j =0;j < n;j++){
				cin>>data[i][j];
			}
		}
		int sum = 0;
		for(int i =0;i<n;i++){
			for(int j =0;j < n;j++){
				data[i][n]+=data[i][j];
				sum +=data[i][j];
			}
		}
		for(int j =0;j < n;j++){
			for(int i =0;i <n;i++){
				data[n][j]+=data[i][j];
			}
		}
		data[n][n]=sum;
		for(int i =0;i <=n;i++){
			for(int j =0;j <=n;j++){
				printf("%5d",data[i][j]);
			}
			cout <<endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;

int main() {
	while (cin >> n) {
		if(!n)break;
		int data[n + 1][n + 1];
		for (int i = 0; i < n; ++i) {
			int tmp=0, sum=0;
			for (int j = 0; j < n; ++j) {
				cin >> tmp;
				data[i][j] = tmp;
				sum += tmp;
			}
			data[i][n] = sum;
		}int sump=0;
		for (int i = 0; i < n; ++i) {
			int summ = 0;
			for (int j = 0; j < n; ++j) {
				summ += data[j][i];
			}
			data[n][i] = summ;
			sump+=summ;
		}data[n][n]=sump;
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				//cout << " " << data[i][j];
				printf("%5d",data[i][j]);
			}
			cout<<endl;
			//printf("\n");
		}
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,x[101][101],i,j,sum;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++) scanf("%d",&x[i][j]);
		}
		for(i=0;i<n;i++){
			sum=0;
			for(j=0;j<n;j++) sum+=x[j][i];
			x[n][i]=0;
			x[n][i]=sum;
		}
		for(i=0;i<=n;i++){
			sum=0;
			for(j=0;j<n;j++) sum+=x[i][j];
			x[i][n]=0;
			x[i][n]=sum;
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%d",x[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int a[100][100];
int n;
int tmp;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(cin >> n,n){
		int x[100];
		rep(i,100) x[i] = 0;
		int sum;
		rep(i,n){
			sum = 0;
			rep(j,n){
				cin >> a[i][j];
				tmp = 10000;
				rep(k,5){
					if(a[i][j]/tmp!=0) break;
					cout << " ";
					tmp /= 10;
				}
				cout << a[i][j];
				sum += a[i][j];
				x[j] += a[i][j];
			}
			tmp = 10000;
			rep(k,5){
				if(sum/tmp!=0) break;
				cout << " ";
				tmp /= 10;
			}
			cout << sum << endl;
		}
		sum = 0;
		rep(i,n){
			sum += x[i];
			tmp = 10000;
			rep(k,5){
				if(x[i]/tmp!=0) break;
				cout << " ";
				tmp /= 10;
			}
			cout << x[i];
		}
		tmp = 10000;
		rep(k,5){
			if(sum/tmp!=0) break;
			cout << " ";
			tmp/=10;
		}
		cout << sum << endl;
	}
}

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

int main(){
	int n;
	int num[11][11];
		
		while(cin >> n,n){
			for(int i=0;i<=n;i++){
				for(int j=0;j<=n;j++){
					num[i][j]=0;
				}
			}
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					cin >> num[i][j];
					num[i][n] += num[i][j];
					num[n][j] += num[i][j];
					num[n][n] += num[i][j];
				}
			}
			for(int i=0;i<=n;i++){
				for(int j=0;j<=n;j++){
					printf("%5d",num[i][j]);
				}
				cout << endl;
			}
	}
	return 0;
}