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 <math.h>
using namespace std;
int main() {
	int n, a[10][10] = {}, sum_h[11] = {}, sum_v[11] = {};
	cin >> n;
	while (n != 0) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> a[i][j];
				cout << a[i][j] << " ";
				sum_h[i] += a[i][j];
				sum_v[j] += a[i][j];
			}
			sum_v[n] += sum_h[i];
			cout << sum_h[i] << endl;
		}
		for (int i = 0; i < n; i++)
			cout << sum_v[i] << " ";
		cout << sum_v[n] << endl;
		cin >> n;
	}
	return 0;
}

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

void print(int a,bool f){
  cout << setw(5) << right << a;
  if(f)cout << endl;
}

int main(){
  int n;
  int a[10][10];
  int row[10],col;

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

    for(int i=0;i<n;i++){
      col = 0;
      for(int j=0;j<n;j++){
	row[j] += a[i][j];
	col += a[i][j];
	print(a[i][j],0);
      }
      print(col,1);
    }

    col = 0;
    for(int i=0;i<n;i++){
      col += row[i];
      print(row[i],0);
    }
    print(col,1);
  }
}

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

using namespace std;

string disp(int a){
	string ans = "     ";
	ans[0] = (a / 10000) + '0';
	ans[1] = (a / 1000) % 10 + '0';
	ans[2] = (a / 100) % 10 + '0';
	ans[3] = (a / 10) % 10 + '0';
	ans[4] = a % 10 + '0';
	
	for(int i = 0; i <= 4; i++){
		if(ans[i] == '0'){
			ans[i] = ' ';
		}else{
			break;
		}
	}
	
	return ans;
}

int main(){
	
	int n;
	
	int mat[20][20];
	
	cin >> n;
	
	while(n != 0){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> mat[i][j];
			}
		}
		
		int sum;
		
		for(int i = 0; i < n; i++){
			sum = 0;
			for(int j = 0; j < n; j++){
				sum += mat[i][j];
			}
			mat[i][n] = sum;
		}
		
		for(int j = 0; j <= n; j++){
			sum = 0;
			for(int i = 0; i < n; i++){
				sum += mat[i][j];
			}
			mat[n][j] = sum;
		}
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				cout << disp(mat[i][j]);
			}
			cout << endl;
		}
		
		cin >> n;
	}
	return 0;
}

C++: #include <cstdio>

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

int main() {
  while(scanf("%d", &n) != EOF, 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, table[20][20];

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

	}

	return 0;
}

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

using namespace std;

int main(){

	int N;
	while(cin>>N,N){
		vector<int> vi(N*N,0),vi2(N*2+1,0);
		for(int i=0;i<N;i++){
			int sum=0;
			for(int j=0;j<N;j++){
				int num;
				cin>>num;
				vi[i*N+j]=num;
				sum+=num;
			}
			vi2[i]=sum;
		}
		for(int i=0;i<N;i++){
			int sum=0;
			for(int j=0;j<N;j++){
				sum+=vi[i+j*N];
				printf("%5d",vi[i*N+j]);
			}
			printf("%5d\n",vi2[i]);
			vi2[N*2]+=vi2[i];
			vi2[N+i]=sum;
		}
		for(int i=0;i<=N;i++){
			printf("%5d",vi2[N+i]);
		}
		cout<<endl;
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){
    while(true) {
        int n;
        cin >> n;
        if (n == 0) break;
        int cell[n+1][n+1];
        int sum_r, sum_c;
        for (int i = 0; i < n; i++) {
            sum_r = 0;
            for (int j = 0; j < n; j++) {
                cin >> cell[i][j];
                sum_r += cell[i][j];
            }
            cell[i][n] = sum_r;
        }
        for (int i = 0; i <= n; i++) {
            sum_c = 0;
            for (int j = 0; j < n; j++) {
                sum_c += cell[j][i];
            }
            cell[n][i] = sum_c;
        }
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                cout << cell[i][j];
                if (j < n) cout << " ";
            }
            cout << endl;
        }
    }
    return 0;
}

C++: #include <stdio.h>

int main(void){
	int matrix[10][10],i,j,dataset;
	scanf("%d",&dataset);
	while(dataset!=0){

		//init add total norm
		for(i=0;i<dataset+1;i++){
			matrix[dataset][i]=0;
			matrix[i][dataset]=0;
		}

		//input and calc
		for(i=0;i<dataset;i++){
			for(j=0;j<dataset;j++){
				scanf("%d",&matrix[i][j]);
				matrix[i][dataset]+=matrix[i][j];
			}
		}

		//calc
		for(j=0;j<dataset+1;j++){
			for(i=0;i<dataset;i++){
				matrix[dataset][j]+=matrix[i][j];
			}
		}

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

C++: #include <stdio.h>
#include <stdlib.h>
int main(){
	int n,i,j;
	while(1){
		int matrix[11][11]={0};
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&matrix[i][j]);
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				matrix[n][j] += matrix[i][j];
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<=n;j++){
				matrix[j][n] += matrix[j][i];
			}
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d ",matrix[i][j]);
			}
			printf("\n");
		}
	}
	return (0);
}

C++: 
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long lon
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)

using namespace std;

int main (void){
    
    int number;
    while(cin >> number,number)
    {
        int math[11][11] ={0};
        REP(i,number)
        {
            REP(j,number)
            cin >> math[i][j];
        }
        REP(i,number)
            REP(j,number)
        math[i][number] += math[i][j];
        REP(i,number)
            REP(j,number)
        math[number][i] += math[j][i];
        REP(i,number)
        REP(j,number)
        math[number][number]+= math[i][j];
        REP(j, number+1)
        REP(i,number+1){
            printf("%5d",math[i][j]);
            if(i == number || (j == number && i == number))
                cout << endl;
            else
                cout << " ";
            
        }
    }
    return 0;
    
  
}