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;
    while(1){
      int sum = 0, s = 0;
      cin >> n;
      if( n == 0) break;
      int poi[n][n];
      for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
         cin >> poi[i][j];
         sum += poi[i][j];
      }
    }
    for(int i = 0;i < n;++i){
    	for(int j = 0;j < n;++j){
    		cout << " " << poi[i][j] << " ";
    		s += poi[i][j];
    		if(j == n -1){
    			cout << " " << s << endl;
    			s = 0;
    		}
    	}
    }
    for(int i = 0;i < n;++i){
    	for(int j = 0;j < n;++j){
          s += poi[j][i];
    	}
    	cout << s << " ";
    	s = 0;
    }
    cout << " " << sum << endl;
   }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<vector<int> >in(n+1);
    rep(i,n){
      int sum=0;
      rep(j,n){
	int tmp;cin>>tmp;
	in[i].pb(tmp);
	sum+=tmp;
      }
      in[i].pb(sum);
    }
    
    rep(i,n+1){
      int sum=0;
      rep(j,n)sum+=in[j][i];
      in[n].pb(sum);
    }
    rep(i,n+1){
      rep(j,n+1)printf("%5d",in[i][j]);
      cout<<endl;
    }
  }
}

C++: #include <stdio.h>

int main(void)
{
	int a[11][11] = {0};
	int n, i, j;

	scanf("%d", &n);
	while (n != 0)
	{
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				scanf("%d", &a[i][j]);

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

		for (j = 0; j < n; j++)
			for (i = 0; i < n; i++)
				a[n][j] += a[i][j];

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

	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<vector<int>>dates(N + 1, vector<int>(N + 1));
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cin >> dates[i][j];
				dates[N][j] += dates[i][j];
				dates[i][N] += dates[i][j];
				dates[N][N] += dates[i][j];
			}
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				printf("%5d", &dates[i][j]);
			}
			printf("\n");
		}
	}
	
	return 0;
}

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

int main(){
	int n;
	while(1){
	cin>>n;
		if(n==0)break;
	vector<vector<int> > a(n+1,vector<int>(n+1));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	
	for(int i=0;i<n;i++){
		int b=0;
		for(int j=0;j<n;j++){
			cout<<a[i][j]<<" ";
			b+=a[i][j];
		}
		cout<<b<<endl;
	}
	
	int d=0;
	
	for(int i=0;i<n;i++){
		int c=0;
		for(int j=0;j<n;j++){
			c+=a[j][i];
		}
		cout<<c<<" ";
		d+=c;
	}
	cout<<d<<endl;
	}
	return 0;
}

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

int main()
{
    int n;
    while (std::cin >> n) {
    
        if (n == 0) break;

        int** p;
        p = new int* [n + 1];
        for (int i = 0; i < n + 1; ++i) {
            p[i] = new int [n + 1];
        }
        
        for (int i = 0; i < n + 1; ++i) {
            for (int j = 0; j < n + 1; ++j) {
                p[i][j] = 0;
            }
        }

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

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

        for (int i = 0; i < n; ++i) {
            p[n][n] += p[i][n];
        }

        for (int i = 0; i < n + 1; ++i) {
            for (int j = 0; j < n + 1; ++j) {
                printf("%5d", p[i][j]);
                if (j == n) std::cout << std::endl;
                
            }
        }

        for (int i = 0; i < n + 1; ++i) {
        delete[] p[i];
        }
    
        delete[] p;
    }
    
    return 0;
}

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

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

return 0;
}

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

int main(void) {
  int n;
  int data[11][11];
  
  while(1) {
    cin >> n;
    if(n==0) break;
    for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin >> data[i][j];
    
    int temp=0;
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	temp+=data[i][j];
      }
      data[i][n] = temp;
      temp=0;
    }
    
    for(int i=0; i<n; i++) {
      for(int j=0; j<n; j++) {
	temp+=data[j][i];
      }
      data[n][i] = temp;
      temp=0;
    }
    
    for(int i=0; i<n; i++) temp+=data[i][n];
    data[n][n] = temp;
    
    for(int i=0; i<=n; i++) {
      for(int j=0; j<=n; j++) {
	printf("%5d", data[i][j]);
      }
      cout << endl;
    }
  }

  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
        int N;
        while(true){
        cin >> N;
        if(N==0)
                break;
        int table[100][100];
        for(int i=0 ; i<N ; i++ ){
                int sum=0;
                for(int j=0 ; j<N ; j++ ){
                        cin >> table[i][j];
                        sum+=table[i][j];
                }
                table[i][N]=sum;
        }
        for(int i=0 ; i<=N ; i++ ){
                table[N][i]=0;
                for(int j=0 ; j<N ; j++ ){
                        table[N][i]+=table[j][i];
                }
        }
        for(int i=0 ; i<=N ; i++ ){
                for(int j=0 ; j<=N ; j++ ){
                        int space=0;
                        if(table[i][j]<10)
                                space=4;
                        else if(table[i][j]<100)
                                space=3;
                        else if(table[i][j]<1000)
                                space=2;
                        else if(table[i][j]<10000)
                                space=1;
                        for(int l=0 ; l<space ; l++ )
                                cout<<" ";
                        cout << table[i][j];
                //      if(j!=N)
                //              cout<<" ";
                }
                cout << endl;
        }
        }
        return 0;
}