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<stdio.h>

int b[11][11];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)
			for(int j=0;j<a;j++)
				scanf("%d",&b[i][j]);
		
		for(int i=0;i<a;i++){
			for(int j=0;j<a;j++){
				b[i][a]+=b[i][j];
			}
		}
		for(int i=0;i<a;i++)
			for(int j=0;j<a;j++)
				b[a][i]+=b[j][i];
		
		for(int i=0;i<a;i++)
			b[a][a]+=b[i][a];
		
		for(int i=0;i<a+1;i++,printf("\n"))
			for(int j=0;j<a+1;j++)
				printf("%5d",b[i][j]);
		for(int i=0;i<a+1;i++)
			for(int j=0;j<a+1;j++)
				b[i][j]=0;
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n;
	short matrix[11][11];

	while(cin >> n, n)
	{
		for(int i=0; i < n; i++) matrix[n][i] = matrix[i][n] = 0;
		matrix[n][n] = 0;
		for(int y=0; y < n; y++) {
			for(int x=0; x < n; x++) {
				cin >> matrix[y][x];
				matrix[n][x] += matrix[y][x];
				matrix[y][n] += matrix[y][x];
				matrix[n][n] += matrix[y][x];
			}
		}
		int nn = n + 1;
		for(int y=0; y < nn; y++) {
			for(int x=0; x < nn; x++) {
					printf("%5d", matrix[y][x]);
			}
			printf("\n");
		}
	}

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <time.h>
#define FOR1 for(int i=0;i<n;i++)
#define FOR2 for(int j=0;j<n;j++)
using namespace std;
int main(){
	int table[50][50],n,sum=0,line=0,row=0;
	while(1){
	cin>>n;
	if(n==0){
		break;
	}
	FOR1{
		FOR2{
			cin>>table[i][j];
			sum+=table[i][j];
		}
	}
	FOR1{
		FOR2{
			printf("%5d",table[i][j]);
			line+=table[i][j];
		}
		printf("%5d\n",line);
		line=0;
	}
	FOR1{
		FOR2{
			row+=table[j][i];
		}
		printf("%5d",row);
		row=0;
	}
	printf("%5d\n",sum);
	sum=0;
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
int main(){
	int n;
	while(cin>>n,n){
		vector< vector<int> > v(n+1,vector<int>(n+1));
		for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin>>v[i][j];
		for(int i = 0; i < n; i++){
			int a = 0;
			for(int j = 0; j < n; j++) a += v[i][j];
			v[i][n] = a;
		}
		{
			int a = 0;
			for(int j = 0; j < n; j++) a += v[j][n];
			v[n][n] = a;
		}
		for(int i = 0; i < n; i++){
			int a = 0;
			for(int j = 0; j < n; j++) a += v[j][i];
			v[n][i] = a;
		}
		for (int i = 0; i <= n; i++){
			for (int j = 0; j <= n; j++){
				printf("%5d",v[i][j]);
			}
			puts("");
		}
	}
    return 0;
}

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

int main(void){
  int n;
  int tmp;

  while(cin >> n && n){
	int colsum[n+1];

	memset(colsum, 0, sizeof(colsum));
	for(int i=0;i<n;i++){
	  int sum=0;
	  for(int j=0;j<n;j++){
		cin >> tmp;
		printf("%5d ", tmp);
		sum += tmp;
		colsum[j] += tmp;
	  }
	  printf("%5d\n", sum);
	  colsum[n] += sum;
	}
	for(int i=0;i<n+1;i++){
	  if(i!=n){
		printf("%5d ", colsum[i]);
	  }else{
		printf("%5d\n", colsum[i]);
	  }
	}
  }
  
}

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

using namespace std;

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

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

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

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

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n;
	while (cin >> n && n) {
		VVI a(n + 1, VI(n + 1));
		rep(i, n)rep(j, n)cin >> a[i][j];
		
		rep(i, n) {
			int sum = 0;
			rep(j, n)sum += a[j][i];
			a[n][i] = sum;
		}
		rep(i, n + 1) {
			a[i][n] = accumulate(all(a[i]), 0);
		}

		rep(i, n + 1){
			rep(j, n + 1)printf("%5d", a[i][j]);
			puts("");
		}
	}
}