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];
				if(k!=4)cout<<" ";
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,hyo[11][11],n,wa[4],wa2[4],sum;
	while(1) {
		scanf("%d",&n);
		if(n==0)  break;
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) scanf("%d",&hyo[i][j]);
		}
		for(i=0;i<n;i++) {
			sum=0;
			for(j=0;j<n;j++) sum+=hyo[i][j];
			wa[i]=sum;
		}
		for(i=0;i<n;i++) {
			sum=0;
			for(j=0;j<n;j++) sum+=hyo[j][i];
			wa2[i]=sum;
		}
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				if(hyo[i][j]==100) printf(" %d ",hyo[i][j]);
				if(hyo[i][j]<100 && hyo[i][j]>=10) printf("  %d ",hyo[i][j]);
			}
			printf("%d\n",wa[i]);
			printf("\n");
		}
		for(i=0;i<4;i++) {
			if(wa2[i]>=1000) printf("%d ",wa2[i]);
			if(wa2[i]>=100 && wa2[i]<1000) printf(" %d ",wa2[i]);
			else printf("   %d ",wa2[i]);
		}
		sum=0;
		for(i=0;i<4;i++) {
			sum+=wa[i];
		}
		if(sum==1000) printf("%d\n",sum);
		if(sum<1000 && sum>=10) printf("%d\n",sum);
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
 
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
  
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
 
int main() {
  int n;
  while(cin >> n, n) {
    int f[12][12] = {};
    rep(i, n) {
      rep(j, n) {
        cin >> f[i][j];
        f[i][n] += f[i][j];
        f[n][j] += f[i][j];
        f[n][n] += f[i][j];
      }
    }
 
    rep(i, n+1) {
      rep(j, n+1) {
        printf("%5d", f[i][j]);
      }
      cout << endl;
    }
  }
}

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

	return 0;
}

C++: #include<iostream>
#include<vector>
int main(){
	int n;
	while(std::cin >> n && n){
		std::vector<std::vector<int> > vec(n+1,std::vector<int>(n+1));
		for(int i = 0; i < n; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){
				std::cin>>vec[i][j];
				sum+=vec[i][j];
			}
			vec[i][n]=sum;
		}
		for(int i = 0; i < n+1; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){
				sum+=vec[j][i];
			}
			vec[n][i]=sum;
		}
		for(int i = 0; i < n+1;++i){
			for(int j = 0; j < n+1; ++j){
				std::cout<<vec[i][j];
				if(j!=n)std::cout<<" ";
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

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

#define BAD "hoshino"

int hoge(int w);
int getKetasu(int n);

int main(){
	int w;
	
	while(1){
	 cin>>w;
	 if(w==0){break;}
	 hoge(w);
	}
	
	return 0;
}

int hoge(int w){	//?????£???????????????
	int t[w+1][w+1];
	int ketasu;
	int x,y,i;
	
	for(y=0;y<w;y++){
	 for(x=0;x<w;x++){
	  cin>>t[x][y];
	 }
	}
	
	for(y=0;y<w;y++){
	 t[w][y]=0;
	 for(x=0;x<w;x++){
	  t[w][y]+=t[x][y];
	 }
	}
	for(x=0;x<=w;x++){
	 t[x][w]=0;
	 for(y=0;y<w;y++){
	  t[x][w]+=t[x][y];
	 }
	}
	
	for(y=0;y<=w;y++){
	 for(x=0;x<=w;x++){
	  if(x!=0){cout<<" ";}
	  ketasu=getKetasu(t[x][w]);
	  for(i=getKetasu(t[x][y]);i<ketasu;i++){cout<<" ";}
	  cout<<t[x][y];
	 }
	}
	
	return 0;
}

int getKetasu(int n){	//?????°?????????
	if(n<10){
	 return 1;
	}else if(n<100){
	 return 2;
	}else if(n<1000){
	 return 3;
	}else{
	 return 4;
	}
}