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++: import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner s = new Scanner(System.in);
        int sub;
        int sum;
        int all;

        while(s.hasNext()){
            sub = s.nextInt();
            all = 0;
            if(sub == 0)
                break;
            int[][] table = new int[sub][sub];
            for(int i = 0; i < sub; i++){
                sum = 0;
                for(int j = 0; j < sub; j++){
                    table[i][j] = s.nextInt();
                    sum += table[i][j];
                    System.out.printf("%5d",table[i][j]);
                    if(j == sub - 1){
                        System.out.printf("%5d", sum);
                        System.out.println();
                    }
                }
            }

            for(int j = 0; j < sub; j++){
                sum = 0;
                for(int i = 0; i < sub; i++){
                    sum += table[i][j];
                }
                all += sum;
                System.out.printf("%5d", sum);
            }
            System.out.printf("%5d", all);
            System.out.println();
        }
        s.close();
    }

}

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

int main()
{
	int n, i, j;
	vector< vector<int> > list(11, vector<int>(11));
	while (cin>>n, n) {
		for (i = 0; i <= n; i++) {
			list[i][n] = 0;
			list[n][i] = 0;
		}
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				cin>>list[i][j];
				list[i][n] += list[i][j];
				list[n][j] += list[i][j];
				list[n][n] += list[i][j];
			}
		}
		for (i = 0; i <= n; i++) {
			for (j = 0; j <= n; j++) {
				cout<<setw(5)<<right<<list[i][j];
			}
			cout<<endl;
		}
	}

	return 0;
}

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

int main(){
	int n;
	while(cin >> n){
		if(n == 0) break;
		else{
			int data[n+2][n+2];

			for (int i = 0; i < n+2; ++i){
				for(int j = 0; j < n+2; j++){					
				data[i][j] = 0;
				}
			}
			
			for (int i = 0; i < n; ++i){
				for(int j = 0; j < n; j++){					
				cin >> data[i][j];
				}
			}
			for (int i = 0; i < n; ++i){
				for(int j = 0; j < n; j++){	
					data[i][n] += data[i][j];
				}
			}
			for (int i = 0; i < n+1; ++i){
				for(int j = 0; j < n; j++){	
					data[n][i] += data[j][i];
				}
			}
			for (int i = 0; i < n+1; ++i){
				for(int j = 0; j < n+1; j++){
					cout.width(5);
					cout << data[i][j];
					// if (j != n) cout<<" ";
				}
				cout << endl;
			}
				
		}
	}
	return 0;
}

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

int n;
int field[1000][1000];
int total;

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

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

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

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

    for (int i=0; i<n+1; i++) {
      printf("%4d", field[i][0]);
      for (int j=1; j<n+1; j++) {
        printf(" %4d", field[i][j]);
      }
      puts("");
    }
  }
}

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

int n;

int solve(int n){
        int format=0,table[1000][1000]={};
        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[n][j] += table[i][j];
                        table[i][n] += table[i][j];
                }
        }
        for(int i=0;i<n;i++){
                table[n][n] += table[i][n];
                table[n][n] += table[n][i];
        }
        table[n][n] /= 2;
        if(table[n][n] < 10){
                format=1;
        }else if(table[n][n] < 100){
                format=2;
        }else if(table[n][n] < 1000){
                format=3;
        }else if(table[n][n] < 10000){
                format=4;
        }
        for(int i=0;i<n+1;i++){
                for(int j=0;j<n+1;j++){
                        cout << setw(format) << table[i][j];
                        cout << " ";
                }
                cout << "" << endl;
        }
}

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

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int matrix[11][11] = {0};
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	cin >>matrix[i][j];
      }
    }
    int suma = 0;
    for(int i=0,sumc,sumr; i<n; i++){
      sumc = 0;
      sumr = 0;
      for(int j=0; j<n; j++){
	sumc+=matrix[i][j];
	sumr+=matrix[j][i];
      }
      suma+=sumc;
      matrix[i][n] = sumc;
      matrix[n][i] = sumr;
    }
    matrix[n][n] = suma;
    for(int i=0; i<=n; i++){
      for(int j=0; j<=n; j++){
	printf("%5d",matrix[i][j]);
      }
      cout <<endl;
    }
  }
  return 0;
}

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

void array(int size){
    int number;
    int sum=0;
    vector< vector<int> > colm(size+1, vector<int>(size+1));
   
   for(int i=0;i<size;i++){
        for(int j=0;j<size;j++){
            cin >> number;
            sum += number;
            colm[i][j] = number; 
        }
        colm[i][size] = sum;
        sum=0;
   }
   //sum=0;
   
   for(int j=0;j<=size;j++){
      for(int i=0;i<size;i++){
        sum += colm[i][j];
      }
      colm[size][j] = sum;
      sum=0;
   }
   
   for(int i=0;i<=size;i++){
       for(int j=0;j<=size;j++){
           cout.width(5);
           cout << colm[i][j];
       }
       cout << endl;
   }
}


int main(){
   int size;
    string str;
    cin >> size;
    cin.ignore();
    while(size != 0){
        array(size);
        cin >> size;
    }
    return 0;
}

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

int main(){
	int n,i,j;
	while(cin >> n && n){
		int table[11][11] = {{0}};
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				cin >> table[i][j];
				table[i][n] += table[i][j];
				table[n][j] += table[i][j];
			}
			table[n][n] += table[i][n];
		}
		for(i = 0;i <= n;i++){
			for(j = 0;j <= n;j++){
				if(table[i][j] / 100 == 0) cout << "   ";
				else cout << "  ";
				cout << table[i][j];
			}
			cout << "\n";
		}
	}
	return 0;
}