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>
#include <string>

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while(cin>>n, n){
        int v[10]={};
        rep(i,n){
            int s=0;
            rep(j,n){
                int t; cin>>t;
                printf("%5d",t);
                s+=t;
                v[j]+=t;
            }
            printf("%5d\n",s);
        }
        int s=0;
        rep(i,n){
            printf("%5d",v[i]);
            s+=v[i];
        }
        printf("%5d\n",s);
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  
  cin >> n;
  
  while(n != 0){
    
    int a[12][12] ={};

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> a[i][j];
	a[i][n] += a[i][j];
	a[n][j] += a[i][j];
      }
      a[n][n] += a[i][n];
    }
    
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	printf("%5d",a[i][j]);
      }
      printf("\n");
    }
    
    cin >> n;
  }

  return (0);
}

C++: #include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n, i, j, a[10], b, c, x;
  while (cin >> n && n > 0) {
    memset(a, 0, sizeof(a));
    c = 0;
    for (i = 0; i < n; i++) {
      b = 0;
      for (j = 0; j < n; j++) {
        scanf("%d", &x);
        printf("%5d", x);
        a[j] += x;
        b += x;
      }
      printf("%5d\n", b);
    }
    for (i = 0; i < n; i++) {
      printf("%5d", a[i]);
      c += a[i];
    }
    printf("%5d\n", c);
  }
  return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int ct,map[10][10],answer[11][11];
	while(1){
		scanf("%d",&ct);
		if(ct==0){
			return 0;
		}
		for(int f1=0;f1<11;f1++){
			for(int f2=0;f2<11;f2++){
				answer[f1][f2]=0;
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				scanf("%d",&map[f1][f2]);
				answer[f1][f2]=map[f1][f2];
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				answer[f1][ct]+=map[f1][f2];
				answer[ct][f1]+=map[f2][f1];
			}
		}
		for(int f1=0;f1<ct;f1++){
			answer[ct][ct]+=answer[f1][ct];
		}
		for(int f1=0;f1<ct+1;f1++){
			for(int f2=0;f2<ct+1;f2++){
				printf("%4d ",answer[f1][f2]);
			}
			printf("\n");
		}
	}
	return 0;
}

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

int main(){

  int n;
  int a[1000][1000],b;

  while(cin >> n, n){

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

    for(int i=0;i<n;i++){
      b = 0;

      for(int j=0;j<n;j++) b += a[i][j];

      a[i][n] = b;

    }

    for(int j=0;j<n;j++){
      b = 0;

      for(int i=0;i<n;i++) b += a[i][j];

      a[n][j] = b;

    }

    b = 0;
    for(int i=0;i<n;i++) b += a[i][n];
    a[n][n] = b;

    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++) printf("%5d",a[i][j]);
      cout << endl;
    }

  }
}

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

int main(){
    int n,m;
    while(cin>>n,n){
        vector<vector<int> >vec;
        for(int i=0;i<n;i++){
            vector<int>v;
            for(int j=0;j<n;j++){
                cin>>m;
                v.push_back(m);
            }
            vec.push_back(v);
        }
        for(int i=0;i<n;i++){
            int s=0;
            for(int j=0;j<n;j++)
                s+=vec[i][j];
            vec[i].push_back(s);
        }
        vector<int>v;
        for(int i=0;i<n+1;i++){
            int s=0;
            for(int j=0;j<n;j++)
                s+=vec[j][i];
            v.push_back(s);
        }
        vec.push_back(v);
        for(int i=0;i<n+1;i++){
            for(int j=0;j<n+1;j++)
                cout<< setfill (' ') << setw (5)<<vec[i][j];
            cout<<endl;
        }
    }
}

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 << data[i][j];
					if (j != n) cout<<" ";
				}
				cout << endl;
			}
				
		}
	}
	return 0;
}

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++){
                if(!j) printf("%3d" ,mat[i][j]);
                else printf(" %3d" ,mat[i][j]);
            }
            cout << endl;
        }
    }
    
    return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int i,j;
  while(1){
    cin >> n;
    if(n==0)break;
    int data[11][11]={0};
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	cin >> data[i][j];
	data[i][n]+=data[i][j];
	data[n][j]+=data[i][j];
	data[n][n]+=data[i][j];
      }
     }
    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	cout.width(5);
	//	cout.fill(' ');
	cout << data[i][j];
      }
      cout << endl;
    }
  }
}

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

int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) {
			break;
		}
		vector<int> col_sum(n + 1);
		for (int i = 0;i != n + 1;++i) {
			col_sum[i] = 0;
		}
		for (int i = 0;i != n;++i) {
			int row_sum = 0;
			for (int j = 0;j != n;++j) {
				int num;
				cin >> num;
				cout << " " << num;
				col_sum[j] += num;
				row_sum += num;
			}
			cout << " " << row_sum << endl;
			col_sum[n] += row_sum;
		}
		for (int i = 0;i != n + 1;++i) {
			cout << " " << col_sum[i];
		}
		cout << endl;
	}
}