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>
using namespace std;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int dt[n+1][n+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>dt[i][j];
			}
		}
		for(int x=0;x<n+1;x++){
			dt[x][n]=0;
		}
		for(int y=0;y<n;y++){
			dt[n][y]=0;
		}
		for(int k=0;k<n;k++){
			for(int l=0;l<n;l++){
				dt[k][n]+=dt[k][l];
			}
		}
		for(int x=0;x<=n;x++){
			for(int y=0;y<n;y++){
				dt[n][x]+=dt[y][x];
			}
		}
		for(int a=0;a<=n;a++){
			for(int b=0;b<=n;b++){
				if(dt[a][b]/10==0)cout<<"    "<<dt[a][b];
				else if(dt[a][b]/100==0)cout<<"   "<<dt[a][b];
				else if(dt[a][b]/1000==0)cout<<"  "<<dt[a][b];
			}
			cout<<endl;
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( n == 0 )
		{
			break;
		}

		vector< vector<int> > table;

		REP( i, 0, n )
		{
			table.PB( vector<int>() );
			int sum = 0;

			REP( j, 0, n )
			{
				int in;
				cin >> in;
				table[i].PB( in );
				sum += in;
			}

			table[i].PB( sum );
		}

		table.PB( vector<int>() );

		REP( i, 0, n + 1 )
		{
			int sum = 0;

			REP( j, 0, n )
			{
				sum += table[j][i];
			}

			table[n].PB( sum );
		}

		REP( i, 0, table.size() )
		{
			REP( j, 0, table[i].size() )
			{
				printf("%5d%c", table[i][j], ( j + 1 == table[i].size() ? '\n' : ' ' ) );
			}
		}
	}

	return 0;
}

C++: #include <stdio.h>

int main()
{
	int in[11][11];
	int n;
	int nyu;

	scanf("%d",&n);

	while(n != 0){
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				in[i][j] = 0;
			}
		}

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

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

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

		scanf("%d",&n);
	}

	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((cin>>n)!=0){
        for(int i=0;i<12;i++)side[i]=0;
        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<stdio.h>
#include<stdafx.h>
int main(){
	int n[9][9] = {0}, x[9] = {0}, y[9] = {0}, a, i, j;
	while(1){
		scanf("%d",&a);
		if(a!=0){
			for(j=0;j<a;j++){
				for(i=0;i<a;i++){
					scanf("%d",&n[j][i]);	
				}
			}
			for(i=0;i<9;i++){
				x[i] = n[0][i]+n[1][i]+n[2][i]+n[3][i]+n[4][i]+n[5][i]+n[6][i]+n[7][i]+n[8][i];
				y[i] = n[i][0]+n[i][1]+n[i][2]+n[i][3]+n[i][4]+n[i][5]+n[i][6]+n[i][7]+n[i][8];
			}
			for(i=0;i<a;i++){
				for(j=o;j<a;j++){
					printf("%5d",n[j][i]);
				}
				printf("%5d\n",y[i]);
			}
			
			for(i=0;i<a;i++){
				printf("%5d",x[i]);
			}
			printf("%5d",x[0]+y[0]+x[1]+y[1]+x[2]+y[2]+x[3]+y[3]+x[4]+y[4]+x[5]+y[5]+x[6]+y[6]+x[7]+y[7]+x[8]+y[8]);
		}else if(a=0){
			break;
		}
	}
	
	return 0;
}

C++: /*
	0102:Matrix-like Computation
*/
#include	<iostream>
#include	<cstdio>

using namespace std;

int main(void) {
	while(1) {
		int n;
		int mat[11][11];
		
		cin >> n;
		
		if(n == 0) { break; }
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				cin >> mat[i][j];
			}
		}
		
		//縦の合計の処理
		for(int i = 0; i < n; i++) {
			int sum = 0;
			for(int j = 0; j < n; j++) {
				sum += mat[i][j];
			}
			
			mat[i][n] = sum;
		}
		
		//横の合計の処理
		for(int i = 0; i < n; i++) {
			int sum = 0;
			for(int j = 0; j < n; j++) {
				sum += mat[j][i];
			}
			
			mat[n][i] = sum;
		}
		
		//合計の合計
		int sum = 0;
		for(int i = 0; i < n; i++) {
			sum += mat[n][i];
		}
		mat[n][n] = sum;
		
		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= n; j++) {
				printf("%5d", mat[i][j]);
			}
			putchar('\n');
		}
	}
	
	return 0;
}

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

int main(){
    int n;

    while(cin>>n,n){
        vector<vector<int>> v(n);
        vector<int> lv(n+1,0);

        for(auto &x:v){
            x.resize(n);
            for(auto &y:x){
                int t;
                cin>>t;
                y=t;
            }
        }

        for(auto &x:v){
            int sum=0;
            for(auto y:x){
                sum+=y;
            }
            x.push_back(sum);

            for(int i=0;i<=n;i++){
                lv[i]+=x[i];
            }
        }

            for(auto x:v){
                for(auto y:x){
                        cout<<setw(5)<<y;
                }
                cout<<endl;
            }

            for(auto x:lv){
                cout<<setw(5)<<x;
            }

            cout<<endl;
    }

    return 0;
}

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

int main(){
   int n,i,j;
   int hyo[20][20];
   
   for(;;){
      cin>>n;
      if(n==0) break;
      
      memset(hyo,0,sizeof(hyo));
      
      for(i=0;i<n;i++){
         for(j=0;j<n;j++){
            cin>>hyo[i][j];
         }
      }
      //ツ可。ツづーツ堕ォツつキ
      for(i=0;i<n;i++){
         for(j=0;j<n;j++){
            hyo[i][n] += hyo[i][j];
         }
      }
      //ツ縦ツづーツ堕ォツつキ
      for(j=0;j<n+1;j++){
         for(i=0;i<n;i++){
            hyo[n][j] += hyo[i][j];
         }
      }
      
      for(i=0;i<n+1;i++){
         for(j=0;j<n+1;j++){
            printf("%5d",hyo[i][j]);
         }
         puts("");
      }
   }
   return 0;
}