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<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	while(cin >> n,n){
		int data[10+1][10+1];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}

		int all_sum = 0;

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




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


		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%3d", data[i][j]);
				if(j != n) cout << " ";
			}
			cout << endl;
		}
	}
}

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;
}