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 <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n;
    while(1){
        cin>>n;
        if(n==0)return 0;
        vector<vector<int>> v(n+1,vector<int>(n+1,0));
        
        rep(i,0,n){
            int sum=0;
            rep(j,0,n){
                cin>>v[i][j];
                sum+=v[i][j];
            }
            v[i][n]=sum;
        }
        
        rep(j,0,n+1){
            int sum=0;
            rep(i,0,n){
                sum+=v[i][j];
            }
            v[n][j]=sum;
        }
        
        rep(i,0,n+1){
            rep(j,0,n+1){
                if(j==0)printf("%5d",v[i][j]);
                else printf("%5d",v[i][j]);
            }
            cout<<endl;
        }
        
        
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<set>
#include<iomanip>
int elem[11][11];
using namespace std;

int main() {
	int n; 
	while(cin >> n, n != 0){
		int allsum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> elem[i][j];
				allsum += elem[i][j];
			}
		}
		elem[n][n] = allsum;
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += elem[i][j];
			}
			elem[i][n] = sum;
		}
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += elem[j][i];
			}
			elem[n][i] = sum;
		}
		
		for(int i=0; i<=n; i++){
			for (int j = 0; j <= n; j++) {
				cout << setw(5) << elem[i][j];
			}cout << endl;
		}
	}
	return 0;
}

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

int main(){
    int n;

    while(cin >> n, n != 0){
        int matrix[n+1][n+1];
        int rowsum, colsum;
        int allsum = 0;

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

        for(int i=0; i<n; i++){
            rowsum = 0;
            for(int j=0; j<n; j++){
                printf("%5d", matrix[i][j]);
                rowsum += matrix[i][j];
            }
            printf("%5d\n", rowsum);
        }

        for(int i=0; i<n; i++){
            colsum = 0;
            for(int j=0; j<n; j++){
                colsum += matrix[j][i];
            }
            allsum += colsum;
            printf("%5d", colsum);
        }
        printf("%5d\n", allsum);
    }

    return 0;
}

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

using namespace std;

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

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

		//output

		for (int i = 0; i < n; i++, all = 0){
			for (int j = 0; j < n; 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; i++){
			printf(" %3d", tdata[i]);
			all += tdata[i];
		}
		printf(" %d3\n", all);
	}
	return 0;
}

C++: #include <cstdio>

int main(){
  int i,j,n,a[10][10],b[10],c[10],sum;
  while(1){

    scanf("%d",&n);
    if(n == 0) break;
    sum = 0;

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

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

  }
  return 0;
}

C++: #include <cstdio>

using namespace std;

int main(void){
	int t[11][11], n, i, j, sum;
	while(1){
		scanf("%d",&n);
		if(!n) break;
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				scanf("%d",&t[i][j]);
			}
		}
		for(i = 0;i < n;i++){
			sum = 0;
			for(j = 0;j < n;j++){
				sum += t[i][j];
			}
			t[i][j] = sum;
			sum = 0;
			for(j = 0;j < n;j++){
				sum += t[j][i];
			}
			t[j][i] = sum;
		}
		sum = 0;
		for(j = 0;j < n;j++){
			sum += t[i][j];
			sum += t[j][i];
		}
		t[i][i] = sum;
		for(i = 0;i < n + 1;i++){
			for(j = 0;j < n + 1;j++){
				printf("%d",t[i][j]);
				if(j != n) printf(" ");
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include<iostream>


using namespace std;


int main(){
	int a[10][10];
	int d, i, j, k, temp,sum=0;

	while (1){
		cin >> d;
		if (d == 0){
			return 0;
		}

		for (i = 0, j = 0; i < d; i++){
			for (j = 0; j < d; j++){
				cin >> a[i][j];
			}
		}

		for (i = 0, j = 0; i < d; i++){
			for (j = 0; j < d; j++){
				cout.width(5);
				cout << a[i][j];
			}
			temp = 0;
			for (k = 0; k < d; k++){
				temp += a[i][k];
			}
			cout.width(5);
			cout << temp << endl;
			sum += temp;
		}
			
		

		for (j = 0; j < d; j++){
			temp = 0;
			for (k = 0; k < d; k++){
				temp += a[k][j];
			}
			cout.width(5);
			cout << temp;
			sum += temp;

		}



		cout.width(5);
		cout << sum/2 << endl;
		sum = 0;
	}
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int a[15][15];
signed main(void)
{
  while(true) {
  int n;
  cin >> n;
  if(!n) break;
  REP(i, n) REP(j, n) cin >> a[i][j];

  REP(i, n) {
    int sum = 0;
    REP(j, n) {
      sum += a[i][j];
      printf("%5d", a[i][j]);
    }
    printf("%5d\n", sum);
  }
  int ret = 0;
  REP(i, n) {
    int sum = 0;
    REP(j, n) {
      sum += a[j][i];
    }
    ret += sum;
    printf("%5d", sum);
  }
  printf("%5d\n", ret);
}

  return 0;
}