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<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
	int ta[100][100],sum[100];
	int n,all;
	while(cin>>n,n){
	all=0;
	for(int i=0;i<100;i++)sum[i]=0,fill(ta[i],ta[i]+100,0);
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>ta[i][j];
	for(int i=0;i<n;i++){
		int tnow=0;
		for(int j=0;j<n;j++){
		cout<<ta[i][j];
		string ss=itos(ta[i][j]);
		for(int i=0;i<5-ss.size();i++)cout<<" ";
		sum[j]+=ta[i][j];
		tnow+=ta[i][j];
		all+=ta[i][j];
		}
		cout<<tnow<<endl;
	}
	for(int i=0;i<n;i++){cout<<sum[i];string ss=itos(sum[i]);for(int i=0;i<5-ss.size();i++)cout<<" ";}
	cout<<all<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<iomanip>
using namespace std;
int main(void)
{
    int n,A=0,ober[10][10],side[10],lon=0;
    while(1){
        for(int i=0;i<12;i++)side[i]=0;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cin>>ober[i][j];
                side[j]+=ober[i][j];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<setw(5)<<ober[i][j]<<" ";
                A+=ober[i][j];
            }
            cout<<setw(5)<<A<<"\n";
            lon+=A;
            A=0;
        }
        for(int i=0;i<n;i++)cout<<setw(5)<<side[i]<<" ";
        cout<<setw(5)<<lon<<"\n";
        lon=0;
    }
}

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

int main() {
	const int MAX_N = 20;
	int N;
	int table[MAX_N][MAX_N];

	while (1) {
		for (int i = 0;i < MAX_N;i++) {
			for (int j = 0;j < MAX_N;j++) {
				table[i][j] = 0;
			}
		}
		cin >> N;
		if (!N)break;
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				cin >> table[i][j];
			}
		}

		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				table[i][N] += table[i][j];
				table[N][j] += table[i][j];
				table[N][N] += table[i][j];
			}
		}

		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				for (int k = 0;k < 5-(log10(table[i][j])+1);k++) {
					cout << " ";
				}
				cout << table[i][j];
			}
			cout << endl;
		}
	}

	return 0;
}

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

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;

#define REP(i, m, n) for (int i = static_cast<int>(m); i < static_cast<int>(n); ++i)

int main()
{
    
    

    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) break;
        
        VVI vvi;

        REP(i, 0, n) {
            vvi.push_back( vector<int>() );
            int sum = 0;
            
            REP(j, 0, n) {
                int in;
                std::cin >> in;
                vvi[i].push_back(in);
                sum += in;
            }
            vvi[i].push_back(sum);
        }

        vvi.push_back( vector<int>() );
        REP(i, 0, n + 1) {
            int sum = 0;
            
            REP(j, 0, n) {
                sum += vvi[j][i];
            }
            
            vvi[n].push_back(sum);
        }
        
        std::cout << "hoge" << std::endl;
        REP(i, 0, vvi.size()) {
            REP(j, 0, vvi[i].size()) {
                std::cout << std::setw(5) << vvi[i][j];
            }
            std::cout << std::endl;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,c;
  while(cin>>n,n){
    int a[n+1][n+1];
    rep(i,n){c=0;rep(j,n){
        cin>>a[i][j];
        c+=a[i][j];
      }
      a[i][n]=c;
    }
    rep(j,n+1){c=0;rep(i,n){
      c+=a[i][j];
    }
    a[n][j]=c;
  }
  rep(i,n+1){rep(j,n+1){printf("%5d",a[i][j]);}cout<<endl;}
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int n;
	while(cin>>n,n) 
	{
		int f[n+1][n+1];
		memset(f,0,sizeof(f));
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin>>f[i][j];
				f[i][n]+=f[i][j];
				f[n][j]+=f[i][j];
				f[n][n]+=f[i][j];
			}
		}
		for(int i = 0; i <= n; ++i)
		{
			for(int j = 0; j <= n; ++j)
			{
				printf("%5d",f[i][j]);
			}
			cout<<endl;
		}
	}
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<set>
#include<iomanip>
int elem[10][10];
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>
#include <stdio.h>
using namespace std;

int main(){
    int number;
    int sum = 0;
    
    while(1){
        cin >> number;
        if (number == 0){
            break;
        }
        
       
        int array[number][number];
        int lastColumn[number];
        int lastRow[number];
        int total=0;
        
        for(int i=0; i<number; i++){
            sum = 0;
            for(int j=0; j<number; j++){
                cin >> array[i][j];
                sum += array[i][j];
            }
            lastColumn[i] = sum;
        }
        
        for(int j=0; j<number; j++){
            sum = 0;
            for(int i=0; i<number; i++){
                sum += array[i][j];
            }
            lastRow[j] = sum;
            total +=sum;
        }
        
        for(int i=0; i<number; i++){
            for(int j=0; j<number; j++){
                printf("%5d", array[i][j]);
            }
            cout << lastColumn[i] <<"\n";
        }
        
        for(int i=0; i<number; i++){
            printf("%5d", lastRow[i]);
         }
        printf("%5d\n", total);

    }
    
    return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int ct,map[10][10],answer[11][11];
	while(1){
		scanf("%d",&ct);
		if(ct==0){
			return 0;
		}
		for(int f1=0;f1<11;f1++){
			for(int f2=0;f2<11;f2++){
				answer[f1][f2]=0;
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				scanf("%d",&map[f1][f2]);
				answer[f1][f2]=map[f1][f2];
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				answer[f1][ct]+=map[f1][f2];
				answer[ct][f1]+=map[f2][f1];
			}
		}
		for(int f1=0;f1<ct;f1++){
			answer[ct][ct]+=answer[f1][ct];
		}
		for(int f1=0;f1<ct+1;f1++){
			for(int f2=0;f2<ct+1;f2++){
				printf("%5d ",answer[f1][f2]);
			}
			printf("\n");
		}
	}
	return 0;
}