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 <bits/stdc++.h>
#define MAX_N 10
using namespace std;
int table[MAX_N+1][MAX_N+1];
int n;

void print() {
    for(int r = 0; r < n + 1; r++) {
        for(int c = 0; c < n + 1; c++) {
            printf("%5d", table[r][c]);
        }
        putchar('\n');
    }
}

int calcVirtual(int x) {
    int sum = 0;
    for(int r = 0; r < n; r++) {
        sum += table[r][x];
    }
    return(sum);
}

int calcHorizontal(int y) {
    int sum = 0;
    for(int r = 0; r < n; r++) {
        sum += table[y][r];
    }
    return(sum);
}

int main(void) {
    while(cin >> n, n != 0) {
        for(int r = 0; r < n; r++) {
            for(int c = 0; c < n; c++) {
                cin >> table[r][c];
            }
        }
        int sum = 0;
        for(int r = 0; r < n; r++) {
            sum += (table[n][r] = calcVirtual(r));
            table[r][n] = calcHorizontal(r);
        }
        table[n][n] = sum;
        print();
    }
}

C++: #include<iostream>
#include<cstdio>
#define MAX 11
using namespace std;
int main(void){
	while(true){
		int n;
		int Mat[MAX][MAX]={{0,},};
		cin >> n;
		if( n == 0 ) break;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> Mat[i][j];
				Mat[i][n] += Mat[i][j];
				Mat[n][j] += Mat[i][j];
			}
			Mat[n][n] += Mat[i][n];
		}
		for(int i = 0; i < n+1; i++){
			for(int j = 0; j < n+1; j++){
				printf("%5d", Mat[i][j]);
			}
			putchar('\n');
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<string>
  
using namespace std;
  
int main(void){
  
   int hyo[11][11];
   int n;
   int sum;

   while(1){
	   for(int i=0;i<10;i++){
		   for(int j=0;j<10;j++){
			   hyo[i][j]=0;
		   }
	   }
	   cin>>n;
	   if(n==0) break;
	   for(int i=0;i<n;i++){
		   for(int j=0;j<n;j++){
			   cin>>hyo[i][j];
		   }
	   }
	   for(int i=0;i<n;i++){
		   sum=0;
		   for(int j=0;j<n;j++){
			   sum+=hyo[i][j];
		   }
		   hyo[i][n]=sum;
	   }
	   for(int j=0;j<=n;j++){
		   sum=0;
		   for(int i=0;i<n;i++){
			   sum+=hyo[i][j];
		   }
		   hyo[n][j]=sum;
	   }
	   for(int i=0;i<=n;i++){
		   for(int j=0;j<=n;j++){
			   printf("%5d",hyo[i][j]);
		   }
		   printf("\n");
	   }
   }

  
   return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(true){
  cin>>n;
  if(!n)break;
  int table[n+1][n+1];
  for(int y=0;y<n;y++){
    int s = 0;
    for(int x=0;x<n;x++){
      cin>>table[x][y];
      s+=table[x][y];
    }
    table[n][y] = s;
  }
  for(int x=0;x<n+1;x++){
    int s = 0;
    for(int y=0;y<n;y++){
      s+=table[x][y];
    }
    table[x][n] = s;
  }
  for(int y=0;y<n+1;y++){
    for(int x=0;x<n+1;x++){
      printf("%5d ",table[x][y]);
    }
    printf("\n");
  }
  }
  return 0;
}

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

int a[11][11];

void init(int n) {
  for(int i = 0; i <= n; ++i) {
	a[i][n] = 0;
	a[n][i] = 0;
  }
}

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

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

int main() {
  int n;
  
  while(scanf("%d", &n)) {
	if(n == 0) break;

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

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

int main(){
    int n;
    int *table;
    while(1){
        std::cin >> n;
        if(!n){
            return 0;
        }
        table = new int [(n + 1) * (n + 1)];
        for(int i = 0; i < n * n; i++){
            std::cin >> table[i / n * (n + 1) + i % n];
        }
        for(int r = 0; r < n; r++){
            for(int c = 0; c < n; c++){
                table[r * (n + 1) + n] += table[r * (n + 1) + c];
                table[n * (n + 1) + c] += table[r * (n + 1) + c];
                table[n * (n + 1) + n] += table[r * (n + 1) + c];
            }
        }
        
        for(int i = 0; i < (n + 1) * (n + 1); i++){
            std::cout << std::setw(5) << table[i];
            if(i % (n + 1) == n){
                std::cout << std::endl;
            }
        }
        delete [] table;
    }
}

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

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s) {int c;for(;;){c=gcu();if(c=='\n'||c==' ')return true;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	int n;
	while ((n = in())) {
		vector<int> v(n + 1);
		for (int i = 0; i < n; ++i) {
			int sum = 0;
			for (int j = 0; j < n; ++j) {
				int d = in();
				printf("%5d", d);
				v[j] += d;
				sum += d;
			}
			v[n] += sum;
			printf("%5d\n", sum);
		}
		for (int d: v)
			printf("%5d", d);
		out('\n');
	}
}

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

int main() {
  int n;
  while(cin >> n && n) {
    int a[n][n];
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) cin >> a[i][j];
    }
    int b[n];
    fill(b,b+n,0);
    for(int i=0; i<n; i++) {
      int sum=0;
      for(int j=0; j<n; j++) {
	printf("%5d",a[i][j]);
	sum+=a[i][j];
	b[j]+=a[i][j];
      }
      printf("%5d\n",sum);
    }
    int sum=0;
    for(int i=0; i<n; i++) {
      printf("%5d",b[i]);
      sum+=b[i];
    }
    printf("%5d\n",sum);
  }
  return 0;
}

C++: #include<iostream>
#include<cstring>
#include<numeric>

int d[11][11];

int main(){
  int n;
	while( std::cin>>n , n ){
		memset(d,0,sizeof(d));
		for( int i=0; i<n; ++i ){
		  for( int l=0; l<n; ++l ){
			  std::cin>> d[l][i];
			}
		}
		for(int i=0; i<=n; ++i){
			for(int l=0;l<=n; ++l){
			  if(l==n && i!=n){
					for( int m=0;m<n;++m )
						d[l][i]+=d[m][i];
					std::cout.width(5);
					std::cout<<d[l][i]<<std::endl;
				}else{
					if(i==n){std::cout.width(5);std::cout<<std::accumulate(d[l],d[l]+n,0)<<(l!=n?"":"\n");}
					else{std::cout.width(5);std::cout<<d[l][i];}
				}
			}
		}
	}
}