Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}

		a := make([][]int, n+1)
		for i := 0; i < n; i++ {
			sum := 0
			stdin.Scan()
			a[i] = make([]int, n+1)
			str := strings.Split(stdin.Text(), " ")
			for j := 0; j < n; j++ {
				a[i][j], _ = strconv.Atoi(str[j])
				sum += a[i][j]
				fmt.Printf("%5d", a[i][j])
			}
			a[i][n] = sum
			fmt.Printf("%5d\n", a[i][n])
		}
		a[n] = make([]int, n+1)
		for i := 0; i <= n; i++ {
			sum := 0
			for j := 0; j < n; j++ {
				sum += a[j][i]
			}
			a[n][i] = sum
			fmt.Printf("%5d", a[n][i])
		}
		fmt.Println()
	}
}

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

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

int main(){
	int n;
	while(cin >> n,n){
		int data[10+1][10+1];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}

		int all_sum = 0;

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




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


		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%3d", data[i][j]);
				if(j != n) cout << " ";
			}
			cout << endl;
		}
	}
}