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

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

C++: #include <iostream>
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++){
                cout << array[i][j] << " ";
            }
            cout << lastColumn[i] <<"\n";
        }
        
        for(int i=0; i<number; i++){
             cout << lastRow[i] << " ";
         }
        cout << total <<"\n";

    }
    
    return 0;
}

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

int main( void )
{
	while (1)
	{
		int n;
		cin >> n;
		if ( n == 0 )
			break;

		vector < vector <int> > T( n+1, vector<int>(n+1, 0) );
		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < n; j++ )
			{
				cin >> T[i][j];
			}
		}

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

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

		for ( int i = 0; i <= n; i++ )
		{
			for ( int j = 0; j <= n; j++ )
			{
				cout << setw(5) << T[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);
        }
        
        
        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 <stdio.h>
//#include <math.h>
using namespace std;

int log10(int n) {
	int keta = 0;
	do{
		n /= 10;
		keta++;
	} while (n > 0);
	return keta;
}

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;
			}
		}
		scanf("%d", &N);
		if (!N)break;
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				scanf("%d", &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]);k++) {
					printf(" ");
				}
				printf("%d", table[i][j]);
			}
			printf("\n");
		}
	}

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
using namespace std;
#define AB(A) for(A=0;A<100;A++)a[A]=0

int main() {
  int n = 0, tmp0 = 0, tmp1 = 0;
  int tmp2 = 0, tmp3, out1 = 0, out2 = 0;
  int a[100];
  scanf("%d", &n);
  while (n) {
    AB(tmp3);
    tmp0 = 0, out2 = 0;
    while (tmp0 < n) {
      tmp1 = 0, out1 = 0;
      while (tmp1 < n) {
        scanf("%d", &tmp2);
        a[tmp1] += tmp2;
        printf("%5d", tmp2);
        out1 += tmp2;
        tmp1++;
      }
      printf("%5d\n", out1);
      a[tmp1] += out1;
      tmp0++;
    }
    tmp0 = 0;
    while (tmp0 < n) {
      printf("%5d", a[tmp0]);
      tmp0++;
    }
    printf("%5d\n", a[tmp0]);
    scanf("%d", &n);
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <stdio.h>
#include <string>
#include <stdlib.h>

using namespace std;

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1){
		int n;
		cin >> n;
		if( n == 0 ) break;
		vector< vector < int > > m;
		vector< int > v;
		for(int i = 0; i < n; i++)
			v.push_back( 0 );
		for(int i = 0; i < n; i++)
			m.push_back( v );

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

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

	}
 
	//while (1){}
	return 0;
}

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

using namespace std;

int main(){
	int n;
	int num;
	int sum, dsum;
	int i, j;
	while(true){
		cin>>n; if(n==0)break;
		vector< vector<int> > v(n+1, vector<int>(n+1));
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				cin>>num;
				v[i][j] = num;
			}
		}
		for(i=0;i<n;i++){
			sum=0;
			for(j=0;j<n;j++){
				sum+=v[i][j];
			}
			v[i][n]=sum;
		}
		dsum=0;
		for(j=0;j<n;j++){
			sum=0;
			for(i=0;i<n;i++){
				sum+=v[i][j];
			}
			v[n][j]=sum;
			dsum+=v[n][j];
		}
		v[n][n]=dsum;
		for(i=0;i<n+1;i++){
			for(j=0;j<n+1;j++){
				cout.width(5);
				cout<<v[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}