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 <math.h>
using namespace std;

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;
			}
		}
		cin >> N;
		if (N == 0)break;
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				cin >> 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])+1);k++) {
					cout << " ";
				}
				cout << table[i][j];
			}
			cout << endl;
		}
	}

	return 0;
}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int n,t;
	int d[20][20];
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		rep(i,n){
			t=0;
			rep(j,n){
				scanf("%d",d[i]+j);
				t+=d[i][j];
			}
			d[i][n]=t;
		}
		rep(i,n+1){
			t=0;
			rep(j,n)t+=d[j][i];
			d[n][i]=t;
		}
		rep(i,n+1){rep(j,n+1)printf("%5d",d[i][j]);puts("");}
	}
	return 0;
}

C++: #include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>


using namespace std;

void Solution()
{
    int n;
    int a[11][11];
    
    while (true)
    {
        cin>>n;
        
        if(n == 0)
        {
            break;
        }
        
        for (int i = 0; i <= n; i++)
        {
            for (int j = 0; j <= n; j++)
            {
                a[i][j] = 0;
            }
        }

        
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                cin>>a[i][j];
                a[i][n] += a[i][j];
            }
        }
        
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j <= n; j++)
            {
                a[n][j] += a [i][j];
            }
        }
        
        for (int i = 0; i <= n; i++)
        {
            for (int j = 0; j <= n; j++)
            {
                cout<<setw(5)<<a[i][j];
            }
            
            cout<<endl;
        }
    }
    
}

int main()
{
    Solution();
    return 0;
}

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

int main(){
int N,num[11][11]={},x;

while(1)
{cin>>N;
if(N==0)break;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++)
{cin>>num[i][j];num[i][N]+=num[i][j];}
}
for(int i=0;i<N;i++)
num[N][N]+=num[i][N];
for(int i=0;i<N;i++)
	for(int j=0;j<N;j++)
num[N][i]+=num[j][i];


for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++)
{if(j>=1)cout<<" ";cout<<num[i][j];}
cout<<endl;
}
}

return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;


int table[4096][4096];
int main()
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == 0)
			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)
		{
			int s = 0;
			for (int j = 0; j < n; ++j)
				s += table[j][i];
			table[n][i] = s;
		}
		for (int i = 0; i <= n; ++i)
		{
			int s = 0;
			for (int j = 0; j < n; ++j)
				s += table[i][j];
			table[i][n] = s;
		}
		for (int i = 0; i <= n; ++i)
		{
			for (int j = 0; j <= n; ++j)
			{
				printf("%5d", table[i][j]);
				if (j == n)
					printf("\n");
				else
					printf(" ");
			}
		}
	}

	return 0;
}

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

int main(){
	int data[11][11];
	int n;
	cin >> n;
	while (n){

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}
		int sum_col[10] = { 0 };
		int sum_low[10] = { 0 };

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sum_col[i] += data[i][j];
				sum_low[i] += data[j][i];
			}
			data[i][n] = sum_col[i];
			data[n][i] = sum_low[i];
		}
		int sum = 0;
		for (int i = 0; i < n; i++){
			sum += data[i][n];
		}
		data[n][n] = sum;
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n + 1; j++){
				printf("%5d", data[i][j]);
			}
			if (i != n)	printf("\n");
		}
		cin >> n;
		if (n) printf("\n");
	}
	
	return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;
 
int main()
{
    int n;
    while(cin>>n){
	if(n==0) return 0;
         int a[11][11]={0};
	 int sum=0;
         for(int i=0;i<n;i++){
             for(int j=0;j<n;j++){
		cin>>a[i][j]; 
                sum+= 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];               
             }
          }
          a[n][n]=sum;
          for(int i=0;i<n+1;i++){
             for(int j=0;j<n+1;j++){
		cout<<setw(5)<<a[i][j];
             }
             cout<<endl;
           }
    }
}

C++: #include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		int d[12][12]={};
		rep(i,0,n) rep(j,0,n){
			cin>>d[i][j]; d[i][n]+=d[i][j];
		}
		rer(i,0,n) rep(j,0,n) d[n][i]+=d[j][i];
		rer(i,0,n){
			rer(j,0,n){
				printf("%5d",d[i][j]);
			}
			printf("\n");
		}
	}
}