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<stdio.h>
int main()
{
	int masu[12][12];
	int n,i,j,w=0,h=0,t=0;
	
	for(;;h=0,w=0,t=0){
		for(i=0;i<11;i++){
			for(j=0;j<11;j++){
				masu[i][j]=0;
			}
		}
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&masu[i][j]);
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				w+=masu[i][j];
				h+=masu[j][i];
			}
			masu[i][j]=w;
			masu[j][i]=h;
			w=0;
			h=0;
		}
		
		for(i=0;i<=n;i++){
			t+=masu[n][i];
		}
		masu[i-1][j]=t;
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d",masu[i][j]);
			}
			puts("");
		}
	}
	return 0;
}

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

int a[11][11];

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

    for (i = 0; i < n; i++){
      for (j = 0; j < n; j++){
        cin >> a[i][j];
      }
    }

    for (i = 0; i < n; i++){
      for (j = 0; j <= n; j++){
        a[i][n] += a[i][j];
      }
    }
    for (j = 0; j <= n; j++){
      for (i = 0; i <= n; i++){
        a[n][j] += a[i][j];
      }
    }
    for (i = 0; i <= n; i++){
      a[i][n] /= 2;
    }
    for (j = 0; j <= n; j++){
      a[n][j] /= 2;
    }

    for (i = 0; i <= n; i++){
      cout << a[i][0];
      for (j = 1; j <= n; j++){
        cout << " " << a[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

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

int map[12][12];

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

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

C++: #include <cstdio>

int matrix[12][12];
int n;

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

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

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

C++: #include <cstdio>

int main(){
  int n;
  
  while(1){
    scanf("%d", &n);
    if(!n) break;
    
    int table[11][11] = {0};
    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][i] += table[j][i];
      }
    }
    
    for(int i=0; i<n; i++)
      table[n][n] += table[n][i];
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++)
	printf("%5d", table[i][j]);
      putchar('\n');
    }
  }
    
  return 0;
}

C++: #include <cstdio>

int main(void)
{
    int data[11][11];
    int n;
    
    while (1){
        scanf("%d", &n);
        if (n == 0) break;
        
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                data[i][j] = 0;
            }
        }
        
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                scanf("%d", &data[i][j]);
                data[i][n] += data[i][j];
                data[n][j] += data[i][j];
                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]);
            }
            printf("\n");
        }
        
    }
    
    return (0);
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



int c[1000][5][5];
int main(){
	CLR(c);
	int cnt=0;
	while(1){
		int N;
		cin>>N;
		if(N==0)break;
		
		int sumr=0;
		REP(i,4){
			REP(j,4){
				cin>>c[cnt][i][j];
				c[cnt][i][4]+=c[cnt][i][j];
				c[cnt][4][j]+=c[cnt][i][j];
			}
			c[cnt][4][4]+=c[cnt][i][4];
		}
		cnt++;
	}
	REP(i,cnt){
		REP(j,5){
			REP(k,5){
				cout<<setw(5)<<right<<c[i][j][k];
				if(k!=4)cout<<" ";
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,hyo[11][11],n,wa[4],wa2[4],sum;
	while(1) {
		scanf("%d",&n);
		if(n==0)  break;
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) scanf("%d",&hyo[i][j]);
		}
		for(i=0;i<n;i++) {
			sum=0;
			for(j=0;j<n;j++) sum+=hyo[i][j];
			wa[i]=sum;
		}
		for(i=0;i<n;i++) {
			sum=0;
			for(j=0;j<n;j++) sum+=hyo[j][i];
			wa2[i]=sum;
		}
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				if(hyo[i][j]==100) printf(" %d ",hyo[i][j]);
				if(hyo[i][j]<100 && hyo[i][j]>=10) printf("  %d ",hyo[i][j]);
			}
			printf("%d\n",wa[i]);
			printf("\n");
		}
		for(i=0;i<4;i++) {
			if(wa2[i]>=1000) printf("%d ",wa2[i]);
			if(wa2[i]>=100 && wa2[i]<1000) printf(" %d ",wa2[i]);
			else printf("   %d ",wa2[i]);
		}
		sum=0;
		for(i=0;i<4;i++) {
			sum+=wa[i];
		}
		if(sum==1000) printf("%d\n",sum);
		if(sum<1000 && sum>=10) printf("%d\n",sum);
	}
	return 0;
}