Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		input := make([][]int, n+1, n+1)
		totalRow := make([]int, n+1, n+1)

		for i := 0; i < n; i++ {
			row := make([]int, n+1, n+1)
			scanner.Scan()

			row = numbers(scanner.Text())

			input[i] = row
			total(totalRow, row)
		}

		input[n] = totalRow

		for xk := range input {
			for yk, yv := range input[xk] {
				if yk == n {
					fmt.Printf("%5d\n", yv)
				} else {
					fmt.Printf("%5d", yv)
				}
			}
		}
	}
}

func total(sum, row []int) {
	for i := 0; i < len(row); i++ {
		sum[i] += row[i]
	}
}

func numbers(s string) []int {
	var n []int
	var sum int
	for _, f := range strings.Fields(s) {
		i, err := strconv.Atoi(f)
		if err == nil {
			n = append(n, i)
			sum += i
		}
	}
	n = append(n, sum)
	return n
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <climits>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    while (cin >> n && n) {
        vector<vector<int>> mat(n+1, vector<int>(n+1, 0));
        for (int i=0; i<n; ++i) {
            for (int j=0; j<n; ++j) {
                cin >> mat[i][j];
                mat[n][j] += mat[i][j];
                mat[i][n] += mat[i][j];
                mat[n][n] += mat[i][j];
            }
        }
        for (int i=0; i<n+1; ++i) {
            for (int j=0; j<n+1; ++j) {
                cout << (j == 0 ? "" : " ") << mat[i][j];
            }
            cout << endl;
        }
    }

    return 0;
}

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;
}