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 <iostream>
#include <cstdio>
#define MAX_N 110
using namespace std;
int main(){
	int n,i,j;
	int a[MAX_N][MAX_N];
	while(1){
		cin >> n;
		if(n==0)break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				cin >> a[i][j];
			}
		}

		int sum1=0,sum[MAX_N];
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				sum[j]+=a[i][j];
				if(i==n){
					a[i][j]=sum[j];
					sum[j]=0;
				}

				sum1+=a[i][j];
				if(j==n){
					a[i][j]=sum1;
					sum1=0;
				}
			}
		}

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

	}
	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++) {
			printf(" ");
			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(" ");
		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;
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
int in[11][11]={0};
int main(){
int n;
while(cin>>n,n){
rep(i,n){
int sum=0,j;
for(j=0;j<n;j++){
int tmp;
cin>>tmp;
sum+=tmp;
in[i][j]=tmp;
printf("%5d",tmp);
}
in[i][j]=sum;
printf("%5d\n",sum);
}

rep(i,n+1){
int sum=0;
rep(j,n){
sum+=in[j][i];
}
if(i!=n)printf("%5d",sum);
else printf("%5d\n",sum);
}
}
}

C++: #include <iostream>
using namespace std;
int main(){
	int n;
	int pt[11][11];
	int sum=0;
	while (true){
		cin >> n;
		if (n == 0) break;
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> pt[i][j];
				sum += pt[i][j];
			}
			pt[i][n] = sum;
			sum = 0;
		}
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n; j++){
				sum += pt[j][i];
			}
			pt[n][i] = sum;
			sum = 0;
		}
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n + 1; j++){
				cout << pt[i][j] << ' ';
			}
			cout << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int t[100][100];
  int n;
  while( cin >> n,n ){
  int c_sum[100],sum[100];
  for(int i = 0 ; i <= n ; i++){
    c_sum[i] = 0;
    sum[i] = 0;
  }
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      cin >> t[j][i];
      sum[i] += t[j][i]; 
      c_sum[j] += t[j][i];
    }
  }
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      printf("%3d ",t[j][i]);
    }
    c_sum[n] += sum[i];
    printf("%3d\n",sum[i]);
  }
  for(int i = 0 ; i < n ; i++)printf("%3d ",c_sum[i]);
  printf("%3d\n",c_sum[n]);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int n;
    int matr[11][11];
    while(cin >> n,n){
        matr[n][n]=0;
        for(int i=0;i<n;i++){
            matr[i][n]=0;
            for(int j=0;j<n;j++){
                if(i==0)matr[n][j]=0;
                cin >> matr[i][j];
                matr[i][n]+=matr[i][j];
                matr[n][j]+=matr[i][j];
                matr[n][n]+=matr[i][j];
            }
        }
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                printf("%5d",matr[i][j]);
            }
            printf("\n");
        }
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

void solve102(int n) {
    vector<int> v(n,0);
    vector<int> w(n,0);
    int k;
    REP(i,n) {
        REP(j,n) {
            cin >> k;
            printf("%5d", k);
            v[i] += k;
            w[j] += k;
        }
        printf("%5d\n", v[i]);
    }
    REP(i,n) {
        printf("%5d", w[i]);
    }
    printf("%5d\n", accumulate(ALL(v), 0));
}

int main() {
    int n;
    while(cin >> n, n) {
        solve102(n);
    }
    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++){
        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 <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

int main(){
	int n;
	while(cin >> n && n != 0){
		vector<vector<int> > ans(n+1, vector<int>(n+1, 0));
	
		for(int i = 0; i < n; i++){
			int total = 0;
			for(int j = 0; j < n; j++){
				cin >> ans[i][j];
				total += ans[i][j];
				ans[n][j] += ans[i][j];
			}
			ans[i][n] = total;
			ans[n][n] += total;
		}

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