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

C++: #include<iostream>
#include<vector>
int main(){
	while(1){
		int a;
		std::cin>>a;
		if(a==0)break;
		std::vector<std::vector<int> > vec(a+1,std::vector<int> (a+1));
		for(int i=0;i<a;i++){
			int b=0;
			for(int j=0;j<a;j++){
				std::cin>>vec[i][j];
				b+=vec[i][j];
			}
			vec[i][a]=b;
		}
		for(int i=0;i<a;i++){
			int c=0;
			for(int j=0;j<a;j++){
				c+=vec[j][i];
			}
			vec[a][i]=c;
		}
		int d=0;
		for(int i=0;i<a;i++){
			d+=vec[a][i];
		}
		vec[a][a]=d;
		for(int i=0;i<a+1;i++){
			for(int j=0;j<a+1;j++){
				if(j!=a)std::cout<<vec[i][j]<<" ";
				else std::cout<<vec[i][j];
			}
			std::cout<<std::endl;
		}
		std::cout<<std::endl;
	}

	return 0;
}