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

int main(){
  int n;
  int a[10][10];
  int sum, amount;
  int i, j;

  while(cin>>n){
    for(i=0; i<n; i++){
      for(j=0; j<n; j++){
        cin>>a[i][j];
      }
    }

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

  return 0;
}

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

int main()
{
	int n;
	while (cin>>n)
	{
		if (n == 0)break;
		int data[11][11] = { 0 };

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

		for (int i = 0; i < n; i++)          //??????????¨????
		{
			for (int j = 0; j < n; j++)
			{
				data[i][n] += data[i][j];
			}
		}

		for (int i = 0; i < n; i++)           //??????????¨????
		{
			for (int j = 0; j < n+1; j++)     //n??????????????????
			{
				data[n][j] += data[i][j];
			}
		}


		for (int i = 0; i < n+1; i++)
		{
			for (int j = 0; j < n+1; j++)
			{
				cout.width(5);
				cout << data[i][j];
			}
			cout << endl;
		}
	}


	return 0;
}

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

using namespace std;

int main()
{
    int n;
    
    while (true) {
        cin >> n;
        if (!n) {
            break;
        }
        vector<vector<int> > v(n + 1, vector<int>(n + 1, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[i][n] += v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[n][i] += v[j][i];
            }
            v[n][n] += v[n][i];
        }
        for (int i = 0; i < n + 1; i++) {
            for (int j = 0; j < n + 1; j++) {
                cout << setw(5) << v[i][j];
            }
            cout << '\n';
        }
    }
}

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

int main(){
	double num[11][11]={};
	int N,x;
int a;
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(num[i][j]==0)a==4;
else if(num[i][j]>0)	a =5-( (int)log10((double)(num[i][j]) )+ 1);
else if(num[i][j]<0)	a =5-( (int)log10((double)(-num[i][j]) )+ 1);
for(int k=0;k<a;k++)
{cout<<" ";}
cout<<num[i][j];}
cout<<endl;


}

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){
num[i][j]=0;
}
}


}

return 0;
}

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 <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n;
    while(1){
        cin>>n;
        if(n==0)return 0;
        vector<vector<int>> v(n+1,vector<int>(n+1,0));
        
        rep(i,0,n){
            int sum=0;
            rep(j,0,n){
                cin>>v[i][j];
                sum+=v[i][j];
            }
            v[i][n]=sum;
        }
        
        rep(j,0,n+1){
            int sum=0;
            rep(i,0,n){
                sum+=v[i][j];
            }
            v[n][j]=sum;
        }
        
        rep(i,0,n+1){
            rep(j,0,n+1){
                if(j==0)printf("%4d",v[i][j]);
                else printf(" %4d",v[i][j]);
            }
            cout<<endl;
        }
        
        
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
	int graph[128][128];
	int num;
	
	while(cin >> num)
	{
		if(!num) break;
		int count = 0;
		int all = 0, las[128];
		for(int i = 0; i < 128; i++)
			las[i] = 0;

		for(int i = 0; i < num; i++)
		{
			for(int j = 0; j < num; j++)
			{
				cin >> graph[i][j];
				count += graph[i][j];
				las[j]  += graph[i][j];
				all += graph[i][j];
				if(j == num - 1) 
				{
					graph[i][j+1] = count;
					count = 0;
				}
				if(i == num - 1)
				{
					graph[i+1][j] = las[j];
				}
				if(i == num - 1 && j == num - 1)
				{
					graph[i+1][j+1] = all;
				}
			}
		}

		for(int i = 0; i < num + 1; i++)
		{
			for(int j = 0; j < num + 1; j++)
			{
				printf("%5d", graph[i][j]);
				if(j != num)
					printf(" ");
			}
			puts("");
		}

	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int dp[15][15];
	int n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>dp[i][j];
	int x=0;
	for(int i=0;i<n;i++){
		int h=0;
		for(int j=0;j<n;j++)
			h+=dp[i][j];
		dp[i][n]=h;
		x+=h;
	}
	for(int i=0;i<n;i++){
		int h=0;
		for(int j=0;j<n;j++)
			h+=dp[j][i];
		dp[n][i]=h;
	}
	dp[n][n]=x;
	for(int i=0;i<=n;i++){
		for(int j=0;j<n;j++)
			cout<<dp[i][j]<<" ";
		cout<<dp[i][n]<<endl;
	}
	}
	return 0;
}