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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



int c[1000][5][5];
int main(){
	CLR(c);
	int cnt=0;
	while(1){
		int N;
		cin>>N;
		if(N==0)break;
		
		int sumr=0;
		REP(i,4){
			REP(j,4){
				cin>>c[cnt][i][j];
				c[cnt][i][4]+=c[cnt][i][j];
				c[cnt][4][j]+=c[cnt][i][j];
			}
			c[cnt][4][4]+=c[cnt][i][4];
		}
		cnt++;
	}
	REP(i,cnt){
		REP(j,5){
			REP(k,5){
				cout<<setw(5)<<right<<c[i][j][k];
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <cstdio>

int main(){
  int n;
  
  while(1){
    scanf("%d", &n);
    if(!n) break;
    
    int table[11][11] = {0};
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	scanf("%d", &table[i][j]);
      }
    }
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	table[i][n] += table[j][i];
	table[n][i] += table[i][j];
      }
    }
    
    for(int i=0; i<n; i++)
      table[n][n] += table[n][i];
    
    for(int i=0; i<=n; i++){
      for(int j=0; j<n; j++)
	printf("%5d", table[i][j]);
      putchar('\n');
    }
  }
    
  return 0;
}

C++: #include <cstdio>

int main(){
  int i,j,n,a[10][10],b[10],c[10],sum;
  while(1){

    scanf("%d",&n);
    if(n == 0) break;
    sum = 0;

    for(i=0;i<n;i++){
      b[i] = 0;
      for(j=0;j<n;j++){
	scanf("%d",&a[i][j]);
	b[i] += a[i][j];
	sum += a[i][j];
      }
    }
    for(i=0;i<n;i++){
      c[i] = 0;
      for(j=0;j<n;j++){
	c[i] += a[j][i];
      }
    }

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

  }
  return 0;
}
#include <cstdio>

int main(){
  int i,j,n,a[10][10],b[10],c[10],sum;
  while(1){

    scanf("%d",&n);
    if(n == 0) break;
    sum = 0;

    for(i=0;i<n;i++){
      b[i] = 0;
      for(j=0;j<n;j++){
	scanf("%d",&a[i][j]);
	b[i] += a[i][j];
	sum += a[i][j];
      }
    }
    for(i=0;i<n;i++){
      c[i] = 0;
      for(j=0;j<n;j++){
	c[i] += a[j][i];
      }
    }

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

  }
  return 0;
}

C++: #include <iostream>
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 <stdio.h>

using namespace std;

int main()
{
	int n;
	int ary[100][100];

while(1)
	{
		cin >> n;

		int sumx = 0;
		int sumy = 0;
		int sumxy = 0;

		if(n == 0)
		{
			break;
		}

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

			for(int i = 0; i < n; i++){
				sumx = 0;
				for(int j = 0; j < n; j++)
				{
					sumx += ary[i][j];
					sumxy += ary[i][j];

					printf("%5d",ary[i][j] );
					//ary[i][j] << " ";//????????´???
				}
				printf("%5d", sumx);
				cout << endl;
			}

			for(int i = 0; i < n; i++){
				sumy = 0;
				for(int j = 0; j < n; j++)
			{
					sumy += ary[j][i];
				}
				printf("%5d", sumy);
			}
			printf("%5d\n", sumxy);
	}
}

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

int main()
{
  int n;
  while(1)
    {
      cin>>n;
      if(n==0)break;
      int m[n][n];
      
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      cin>>m[i][j];
	    }
	}
      
      int gyousum=0,retusum=0,allsum=0;
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      cout<<setw(5)<<m[i][j];
	      gyousum+=m[i][j];
	      allsum+=m[i][j];
	    }
	  cout<<setw(5)<<gyousum<<"\n";
	  gyousum=0;
	}
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      retusum+=m[j][i];
	    }

	  cout<<setw(5)<<retusum;
	  retusum=0;
	}
      cout<<setw(5)<<allsum<<"\n";
      allsum=0;
      }
  return 0;
}