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 <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		vvi a(n+1,vi(n+1));
		rep(i,n){
			rep(j,n){
				cin>>a[i][j];
				a[i][n]+=a[i][j];
				a[n][j]+=a[i][j];
			}
		}
		a[n][n]=accumulate(allof(a[n]),0);
		rep(i,a.size()){
			rep(j,a[i].size())
				cout<<setw(5)<<a[i][j];
			cout<<endl;
		}
		
	}
	
	return 0;
}

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

/*
int log10(int n) {
	int keta = 0;
	do{
		n /= 10;
		keta++;
	} while (n > 0);
	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-((table[i][j]==0)? 1 : log10(table[i][j]) + 1);k++) {
					printf(" ");
				}
				printf("%d", table[i][j]);
			}
			printf("\n");
		}
	}

	return 0;
}

C++: #include<iostream>
int main() {
	int n;
	while (std::cin >> n){
		if (n == 0)break;
		int l[11][11];
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++)
				std::cin >> l[i][j];
			l[i][n] = 0;
			for (int j = 0; j < n; j++)
				l[i][n] += l[i][j];
		}
		for (int i = 0; i < n + 1; i++){
			l[n][i] = 0;
			for (int j = 0; j < n; j++){
				l[n][i] += l[j][i];
			}
		}
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n + 1; j++){
				std::cout.width(5);
				std::cout << l[i][j];
			}
			std::cout << std::endl;
		}
	}
}

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

C++: #include <iostream>
#include <iomanip>
#include<vector>
using namespace std;
int main()
{
	while(1)
	{
		int N;
		cin >> N;
		if(N == 0)
		{
			return 0;
		}

		vector<vector<int>> map;

		//??????????????????
		for(int i = 0; i < N+1; i++)
		{
			vector<int> column;
			for(int j = 0; j < N + 1; j++)
			{
				if(i == N)
				{
					column.push_back(0);
				}
				else if(j != N)
				{
					int value;
					cin >> value;
					column.push_back(value);
				}
				else
				{
					column.push_back(0);
				}

			}  
			map.push_back(column);
		}
		//?????????????¨????
		int totalSum = 0;
		//????????????????¨????
		for(int i = 0; i < N; i++)
		{
			int sum = 0;
			for(int j = 0; j < N; j++)
			{
				sum += map[i][j];
			}
			map[i][N] = sum;
		}
		//????????????????¨????
		for(int i = 0; i < N; i++)
		{
			int sum = 0;
			for(int j = 0; j < N; j++)
			{
				sum += map[j][i];
			}
			map[N][i] = sum;
			totalSum += sum;
		}
		//????????????????¨???????????????£??\
		map[N][N] = totalSum;

		for(int i = 0; i < N + 1; i++)
		{
			for(int j = 0; j < N + 1; j++)
			{
				cout << setw(5) << right << map[i][j];
			}
			cout << endl;
		}
	}

}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int n;
int t[11][11];
int main(){
  while(cin>>n){
    if(n==0)break;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>t[i][j];
      }
    }
    for(int j=0;j<n;j++){
      t[n][j]=0;
      for(int i=0;i<n;i++){
	t[n][j]+=t[i][j];
      }
    }
    for(int i=0;i<=n;i++){
      t[i][n]=0;
      for(int j=0;j<n;j++){
	t[i][n]+=t[i][j];
      }
    }

    for(int i=0;i<=n;i++){
      
      for(int j=0;j<=n;j++){
	if(j)cout<<' ';
	printf("%5d",t[i][j]);
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>
int d[10][10];
int t[10][10];
int n;
int i,j;
int res;

int main(){
	while(1){
	scanf("%d",&n);
	if(n==0)return 0;
	for(i=0;i<n;i++)for(j=0;j<n;j++){
		scanf("%d",&d[i][j]);
		t[i][j]=0;
	}
	for(i=0;i<n;i++){
		res=0;
		for(j=0;j<n;j++){
			res+=d[i][j];
			printf("%5d",d[i][j]);
		}
		printf("%5d\n",res);
	}
	for(i=0;i<n;i++){
		res=0;
		for(j=0;j<n;j++){
			res+=d[j][i];
		}
		printf("%5d",res);
	}
	res=0;
	for(i=0;i<n;i++)for(j=0;j<n;j++){
		res+=d[i][j];
	}
	printf("%5d\n",res);
	}
}

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

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

int main()
{
    int n=0,i=0,j=0,k=0,sum=0,ii=0;

        int aa[128][128];
    for(ii=0;;ii++){
            //int bb[]={};
        cin >> n;
        if(n==0)break;
        //if(n==0 && x==0)break;
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                cin >> k;
                aa[i][j]=k;
                sum+=k;
            }
            aa[i][j]=sum;
            sum=0;
        }


        for(j=0;j<n+1;j++){
            for(i=0;i<n;i++){
                sum+=aa[i][j];
            }
        aa[i][j]=sum;
        sum=0;
        }
        for(i=0;i<n+1;i++){
            for(j=0;j<n+1;j++){
                cout << aa[i][j];
                if(j<n)cout << ' ';
            }
            cout << endl;
        }
    }
     cout << endl;


}