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

int main() {
	
	int n;
	int *elm;
	int sum,total;
	
	while(cin>>n,n){
		
		elm = new int[n*n];
		
		for(int i=0;i<n*n;++i){
			cin >> elm[i];
		}
		
		
		
		for( int i=0;i<n;++i){
			sum = 0;
			for(int j=0;j<n;++j){
				cout << setw(5) << elm[j+i*n];
				sum += elm[j+i*n];
			}
			cout << setw(5) << sum;
			cout << endl;
		}
		
		total = 0;
		for(int i=0;i<n;++i){
			sum = 0;
			for(int j=0;j<n;++j){
				sum += elm[j*n+i];
			}
			cout<<setw(5)<<sum;
			total += sum;
		}
		cout<<setw(5)<<total<<endl;
		delete[]elm;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    while(1)
    {
        int n;
        cin>>n;if(!n)return 0;
        int t[11][11]={{0}};
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                cin>>t[i][j];
            }
        }
        for(int i=0;i<n;++i){
            int sum=0;
            for(int j=0;j<=n;++j){
                if(j!=n){
                    sum+=t[i][j];
                    t[n][n]+=t[i][j];
                }
                if(j==n){
                    t[i][j]=sum;
                }
            }
        }
        for(int j=0;j<n;++j){
            int sum=0;
            for(int i=0;i<=n;++i){
                if(i!=n){
                    sum+=t[i][j];
                }
                if(i==n){
                    t[i][j]=sum;
                }
            }
        }
        for(int i=0;i<=n;++i){
            for(int j=0;j<=n;++j){
                printf("%5d",t[i][j]);
            }
            cout<<endl;
        }
    }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int table[20][20];
		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 j = 0; j <= n; j++){
			//table[n]
			int sum=0;
			for(int i = 0; i < n; i++){
				sum+=table[i][j];
			}
			table[n][j]=sum;
		}
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%5d",table[i][j]);
			}
			cout<<endl;
		}
	}

	return 0;
}

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

int main(){
  int n,sumw,sumh;
  while(1){
    cin>>n;
    if(n==0)break;
    int array[n+1][n+1];
    for(int i=0;i<n;i++){
      sumw=0;
      for(int j=0;j<n;j++){
	cin>>array[i][j];
	sumw+=array[i][j];
      }
      array[i][n]=sumw;
    }
    for(int i=0;i<n+1;i++){
      sumh=0;
      for(int j=0;j<n;j++){
	sumh+=array[j][i];
      }
      array[n][i]=sumh;
    }
    for(int i=0;i<n+1;i++){
      for(int j=0;j<n+1;j++){
	printf("%5d",array[i][j]);
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,x[101][101],i,j,sum,y;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++) scanf("%d",&x[i][j]);
		}
		for(i=0;i<n;i++){
			sum=0;
			for(j=0;j<n;j++) sum+=x[j][i];
			x[n][i]=0;
			x[n][i]=sum;
		}
		for(i=0;i<=n;i++){
			sum=0;
			for(j=0;j<n;j++) sum+=x[i][j];
			x[i][n]=0;
			x[i][n]=sum;
		}
		y=0;
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				y=x[i][j];
				if(y==0) y=1;
				while(y<1000){
					printf(" ");
					y*=10;
				}
				printf("%d ",x[i][j]);
			}
			printf("\n");
		}
	}
	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<<"\n";
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,i,j,t,ans1=0,ans2=0,ans3=0,list[100][100]={2};
  while(1){
  cin >> n;
  if(n==0){
    break;
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      cin >> list[i][j];
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      ans1=ans1+list[i][j];
      ans2=ans2+list[j][i];
    }
    list[i][j]=ans1;
    ans3=ans3+ans1;
    ans1=0;
    list[j][i]=ans2;
    ans2=0;
  }
  list[i][j]=ans3;
  ans3=0;
  for(i=0;i<n+1;i++){
    for(j=0;j<n+1;j++){
      printf("%5d",list[i][j]);
    }
    cout << endl;
  }
  }
  return (0);
}

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

int main(){
	while(1){
		int n;
		int map[11][11];
		int row[11];
		int line[11];
		int allSum = 0;
		scanf("%d", &n );
		if( n == 0 ) break;

		for( int y=0; y<n; y++ ){
			for( int x=0; x<n; x++ ){
				scanf("%d", &map[x][y]);
			}
		}
		for( int y=0; y<n; y++ ){
			line[y] = 0;
			for( int x=0; x<n; x++ ){
				line[y] += map[x][y];
			}
		}
		for( int x=0; x<n; x++ ){
			row[x] = 0;
			for( int y=0; y<n; y++ ){
				row[x] += map[x][y];
			}
		}
		for( int i=0; i<n; i++ ){
			allSum += row[i];
		}
		for( int y=0; y<n; y++ ){
			for( int x=0; x<n; x++ ){
				printf("%5d", map[x][y]);
			}
			printf("%5d\n", line[y] );
		}
		for( int x=0; x<n; x++ ){
			printf("%5d", row[x]);
		}
		printf("%5d\n", allSum );
	}
	return 0;
}

C++: #include <iostream>
#include <iomanip>
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 << setw(5) << x;
				sum += x;
				array[i] += x;
			}
			cout << setw(5) << sum << "\n";
		}
		for(i=0;i<n;i++){
			cout << setw(5) << array[i];
			sumsum += array[i];
		}
	cout << setw(5) << sumsum << "\n";
	sumsum=0;
	}
	return 0;
}

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

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector< vector<int> > mat(n + 1, vector<int>(n + 1));
		for(int i = 0; i < n; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){
				cin >> mat[i][j];
				sum += mat[i][j];
			}
			mat[i][n] = sum;
		}
		for(int i = 0; i <= n; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){ sum += mat[j][i]; }
			mat[n][i] = sum;
		}
		for(int i = 0; i <= n; ++i){
			for(int j = 0; j <= n; ++j){
				printf("%5d", mat[i][j]);
			}
			puts("");
		}
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int n, j, i;
	int mat[15][15];
	
	while(1){
		scanf("%d", &n);
		
		if (n == 0) break;
		
		
		for (i = 0; i <= n; i++){
			for (j = 0; j <= n; j++){
				mat[i][j] = 0;
			}
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				scanf("%d", &mat[i][j]);
				mat[i][n] += mat[i][j];
			}
		}
		
		for (i = 0; i <= n; i++){
			for (j = 0; j < n; j++){
				mat[n][i] += mat[i][j];
			}
		}
		
		for (i = 0; i <= n; i++){
			for (j = 0; j <= n; j++){
				printf("%5d", mat[i][j]);
			}
			puts("");
		}
	}
	return (0);
}