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<iostream>
#include<iomanip>
#include<vector>
using namespace std;

vector<vector<int> > data;

void init(){
  data.clear();
}

bool input(){
  int n;
  cin>>n;
  if(n==0)return false;

  for(int i=0;i<n;i++){
    vector<int> vtmp;
    for(int j=0;j<n;j++){
      int tmp;
      cin>>tmp;
      vtmp.push_back(tmp);
    }
    data.push_back(vtmp);
  }
  return true;
}

void solve(){
  vector<int> last;
  last.resize(data[0].size()+1);
  for(int i=0;i<data.size();i++){
    int tmp=0;
    for(int j=0;j<data[i].size();j++){
      tmp+=data[i][j];
      last[j]+=data[i][j];
      last[last.size()-1]+=data[i][j];
    }
    data[i].push_back(tmp);
  }
  data.push_back(last);
}


int main(){
  while(init(),input()){
    solve();
    for(int i=0;i<data.size();i++){
      for(int j=0;j<data[i].size();j++){
        cout<<setw(5)<<data[i][j];
      }cout<<endl;
    }
  }
}

C++: #include<iostream>
#include<iomanip>
using namespace std;
int main(void)
{
    int n,A=0,ober[10][10],side[10],lon=0;
    while(1){
        for(int i=0;i<12;i++)side[i]=0;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cin>>ober[i][j];
                side[j]+=ober[i][j];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<setw(5)<<ober[i][j]<<" ";
                A+=ober[i][j];
            }
            cout<<setw(5)<<A<<"\n";
            lon+=A;
            A=0;
        }
        for(int i=0;i<n;i++)cout<<setw(5)<<side[i]<<" ";
        cout<<setw(5)<<lon<<"\n";
        lon=0;
    }
}

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

int main(){
    int number;
    int sum = 0;
    
    while(1){
        cin >> number;
        if (number == 0){
            break;
        }
        
       
        int array[number][number];
        int lastColumn[number];
        int lastRow[number];
        int total=0;
        
        for(int i=0; i<number; i++){
            sum = 0;
            for(int j=0; j<number; j++){
                cin >> array[i][j];
                sum += array[i][j];
            }
            lastColumn[i] = sum;
        }
        
        for(int j=0; j<number; j++){
            sum = 0;
            for(int i=0; i<number; i++){
                sum += array[i][j];
            }
            lastRow[j] = sum;
            total +=sum;
        }
        
        for(int i=0; i<number; i++){
            for(int j=0; j<number; j++){
                printf("%5d ", array[i][j]);
            }
            cout << lastColumn[i] <<"\n";
        }
        
        for(int i=0; i<number; i++){
            printf("%5d ", lastRow[i]);
         }
        printf("%5d\n", total);

    }
    
    return 0;
}

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

int main(void){
	int n,tmp;
	while ( cin >> n ,n){
		int list[11][11]={0};
		for(int j=0;j<n;j++)
			for(int i=0;i<n;i++)
				cin >> list[i][j];
		for(int j=0;j<n;j++)
			for(int i=0;i<n;i++)
				list[n][j]+=list[i][j];
		for(int i=0;i<=n;i++)
			for(int j=0;j<n;j++)
				list[i][n]+=list[i][j];
		for(int j=0;j<=n;j++){
			for(int i=0;i<=n;i++){
				printf("%5d",list[i][j]);
				//printf(i?" ":"");
			}
			printf("\n");
		}
	}
	return 0;
}

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

int main()
{
	int n,sum,i,sumsum=0;
	int array[11]={0};
	while(1){
		for(i=0;i<11;i++) array[i]=0;
		cin >> n;
		int loop = n;
		if(!n)break;
		while(loop--){
			sum = 0;
			for(i=0;i<n;i++){
				int x;
				cin >> x;
				cout << x << "\t";
				sum += x;
				array[i] += x;
			}
			cout << sum << "\n";
		}
		for(i=0;i<n;i++){
			cout << array[i] << "\t";
			sumsum += array[i];
		}
	cout << sumsum << "\n";
	sumsum=0;
	}
	return 0;
}

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