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>
using namespace std;
int main()
{
	int n,sum=0,sumy=0;
	while (1){
		sum = 0;
		sumy = 0;
		cin >> n;
		if (n == 0)break;
		int ma[101][101] = { 0 };
		for (int i = 0; i < n; i++){
			sum = 0;
			for (int i2 = 0; i2 < n; i2++){
				cin >> ma[i][i2];
				sum += ma[i][i2];

			}
			sumy += sum;
			ma[i][n] += sum;
		}
		ma[n][n] += sumy;
		for (int i = 0; i < n; i++){
			sum = 0;
			for (int i2 = 0; i2 < n; i2++){
				sum += ma[i2][i];
				sumy += sum;
			}
			ma[n][i] += sum;
		}
		n++;
		for (int i = 0; i < n; i++){
			for (int i2 = 0; i2 < n; i2++){
				printf("%5d", ma[i][i2]);
			}
			cout << endl;
		}
	}
}

C++: //#define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 11
#define HO 6
int main(void)
{
	int n;
	while (1) {
		scanf_s("%d", &n);
		if (n == 0) break;
		int date[MAX][MAX] = { 0 };
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				scanf_s("%d", &date[i][j]);
				date[i][n] += date[i][j];
				date[n][j] += date[i][j];
				date[n][n] += date[i][j];
			}
		}
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				printf("%5d", date[i][j]);
			}
			printf("\n");
		}
		
	}
}

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<<d[l][i]<<std::endl;
				}else{
					if(i==n)std::cout<<std::accumulate(d[l],d[l]+n,0)<<(l!=n?" ":"\n");
					else std::cout<<d[l][i]<<" ";
				}
			}
		}
	}
}

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

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
	int N;
	while(cin>>N,N){
		int chart[11][11]={};
		for(int i=0;i<N;i++)for(int j=0;j<N;j++) cin>>chart[i][j];
		for(int i=0;i<=N;i++){
			int sumW=0,sumH=0;
			for(int j=0;j<N;j++){
				sumW += chart[i][j];
				sumH += chart[j][i];
			}
			chart[i][N] = sumW;
			chart[N][i] = sumH;
		}
		for(int i=0;i<=N;i++){
			for(int j=0;j<=N;j++){
				printf("%5d",chart[i][j]);
			}puts("");
		}
	}
    return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<set>
int elem[10][10];
using namespace std;

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

C++: #include <stdio.h>
//#include <math.h>
using namespace std;

int log10(int n) {
	int keta = 0;
	while (n > 0) {
		n /= 10;
		keta++;
	}
	return keta;
}

int main() {
	const int MAX_N = 20;
	int N;
	int table[MAX_N][MAX_N];

	while (1) {
		for (int i = 0;i < MAX_N;i++) {
			for (int j = 0;j < MAX_N;j++) {
				table[i][j] = 0;
			}
		}
		scanf("%d", &N);
		if (!N)break;
		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];
				table[N][N] += table[i][j];
			}
		}

		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				for (int k = 0;k < 5-log10(table[i][j]);k++) {
					printf(" ");
				}
				printf("%d", table[i][j]);
			}
			printf("\n");
		}
	}
printf("\n");

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int n;
  while (cin >> n, n){
    int table[n][n], x[n], y[n], sum = 0;
    REP(i, n){
      REP(j, n) cin >> table[i][j];
      x[i] = y[i] = 0;
    }
    REP(i, n){
      cout << setw(5) << right << table[i][0];
      x[i] = table[i][0];
      FOR(j, 1, n){
        cout << setw(5) << right << table[i][j];
        x[i] += table[i][j];
      }
      cout << setw(5) << right << x[i] << endl;
    }
    REP(i, n){
      REP(j, n) y[i] += table[j][i];
    }
    cout << setw(5) << right << y[0];
    FOR(i, 1, n) cout << setw(5) << right << y[i];
    REP(i, n) sum += x[i];
    cout << setw(5) << right << sum << endl;
  }
}

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

int main(){
    int n,m;
    vector<vector<int> >vec;
    while(cin>>n,n){
        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 <bits/stdc++.h>

using namespace std;


int main(void) {
    int n;
    while (scanf("%d", &n), n) {
        int a[110][110] = {};
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                scanf("%d", &a[i][j]);
        
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                a[i][n] += a[i][j];
        
        for (int j = 0; j <= n; j++)
            for (int i = 0; i < n; i++)
                a[n][j] += a[i][j];
        
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++)
                printf("%5d", a[i][j]);
            puts("");
        }
    }

    return 0;
}