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 <cstdio>
using namespace std;
#define MAX 11

int main(){
    int n,mat[MAX][MAX];
    
    while(true){
        for(int i = 0 ; i < MAX ; i++)
            for(int j = 0 ; j < MAX ; j++)
                mat[i][j] = 0;
        
        cin >> n;
        if(!n) break;
        
        for(int i = 0 ; i < n ; i++)
            for(int j = 0 ; j < n ; j++)
                cin >> mat[i][j];
        
        int sum = 0;
        for(int i = 0 ; i <= n ; i++){
            for(int j = 0 ; j <= n ; j++){
                sum += mat[i][j];
                if(j == n){
                    mat[i][j] = sum;
                    sum = 0;
                }
                
            }
        }
        
        for(int j = 0 ; j <= n ; j++){
            for(int i = 0 ; i <= n ; i++){
                sum += mat[i][j];
                if(i == n){
                    mat[i][j] = sum;
                    sum = 0;
                }
            }
        }
        
        int e = 0;
        for(int i = 0 ; i < n ; i++){
            e += mat[n][i];
            if(i == n-1) mat[n][n] = e;
        }
        
        for(int i = 0 ; i <= n ; i++){
            for(int j = 0 ; j <= n ; j++){
                 printf("%5d" ,mat[i][j]);
            }
            cout << endl;
        }
    }
    
    return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,data[11][11];
  while(1){
    for(int i=0;i<11;i++){
      for(int j=0;j<11;j++){
	data[i][j]=0;
      }
    }
    cin>>n;
    if(n==0){break;}
    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];
	data[n][i]+=data[j][i];
	data[n][n]+=data[i][j];
      }
    }
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	printf("%5d",data[i][j]);
	if(j<n){
	cout<<" ";
	}
      }
      cout<<endl;
    }
  }
  return 0;
}

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

int main(){

  int n,i,j;

  while(1){

    scanf("%d",&n);

    if(n==0){
      break;
    }

  int data[10][10]={0};
  int sum[10]={0};
  int sum2[10]={0};
  int sum3=0;

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

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

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

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

  }

  return 0;
}

C++: #include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<deque>
using namespace std;

string convert(int x){
	stringstream buf;
	buf<<x;
	while(buf.str().size()<5){
		string tmp = buf.str();
		buf.str("");
		buf<<" "<<tmp;
	}
	return buf.str();
}

int main(){
	int n;
	cin>>n;
	stringstream buf;
	while(n!=0){
		vector< vector<int> > table;
		for(int x=0;x<n;++x){
			vector<int> tmp;
			int sum = 0;
			for(int i=0;i<n;++i){
				int j;cin>>j;
				tmp.push_back(j);
				sum +=j;
			}
			tmp.push_back(sum);
			table.push_back(tmp);	
		}
		vector<int> tmp;
		for(int x=0;x<table[0].size();++x){
			int sum = 0;
			for(int y=0;y<table.size();++y){
				sum += table[y][x];
			}
			tmp.push_back(sum);
		}
		table.push_back(tmp);

		for(int x=0;x<table.size();++x){
			for(int y=0;y<table[x].size();++y){
				buf<<convert(table[x][y]);
			}
			buf<<"\n";
		}
		cin>>n;
	}
	cout<<buf.str();
	return 0;
}

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

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int n;
	
	while(cin >> n, n) {
		vvi field(n+1, vi(n+1, 0));

		REP(i, n) {
			REP(j, n) {
				cin >> field[i][j];		
			}
		}

		REP(i, n) {
			REP(j, n) {
				field[i][n] += field[i][j];
				field[n][j] += field[i][j];
				field[n][n] += field[i][j];
				printf("%5d", field[i][j]);
			}
			printf("%5d\n", field[i][n]);
		}

		REP(i, n+1) {
			printf("%5d", field[n][i]);
		}

		printf("\n");
	}

	
	return 0;
}

C++: #include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int n[102], tn=0,ni=0,all = 0, i = 0,h=0;
	int data[1024][10];
	int tdata[10] = { 0 };
	
	//input
	while (1){
		cin >> n[ni];
		if (n[ni] == 0)break;
		tn += n[ni];

		for (; i < tn; i++){
			for (int j = 0; j < n[ni]; j++){
				cin >> data[i][j];
			}
		}
		ni++;
	}


	//output
	for (int k = 0; k < ni; k++){
		for (int i=0; i < n[k]; i++, all = 0,h++){
			for (int j = 0; j < n[k]; j++){
				printf("%5d", data[h][j]);
				all += data[h][j];
				tdata[j] += data[h][j];
			}
			printf("%5d\n", all);
		}

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

		for (int i = 0; i < n[k]; i++){
			tdata[i] = 0;
		}
		all = 0;
	}
	return 0;
}

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

int main(){
	int n, h[11][11];
	while(scanf("%d", &n)){
		if(!n)break;
		for(int i = 0;i < n;i++){
			int num = 0;
			for(int j = 0;j < n;j++){
				scanf("%d", &h[i][j]);
				num += h[i][j];
				printf("%5d", h[i][j]);
			}
			h[i][n] = num;
			printf("%5d\n", num);
		}
		
		for(int i = 0;i <= n;i++){
			int num = 0;
			for(int j = 0;j < n;j++)num += h[j][i];
			printf("%5d", num);
		}
		printf("\n");
	}
}