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>
using namespace std;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int dt[n+1][n+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>dt[i][j];
			}
		}
		for(int x=0;x<n+1;x++){
			dt[x][n]=0;
		}
		for(int y=0;y<n;y++){
			dt[n][y]=0;
		}
		for(int k=0;k<n;k++){
			for(int l=0;l<n;l++){
				dt[k][n]+=dt[k][l];
			}
		}
		for(int x=0;x<=n;x++){
			for(int y=0;y<n;y++){
				dt[n][x]+=dt[y][x];
			}
		}
		for(int a=0;a<=n;a++){
			for(int b=0;b<=n;b++){
				if(dt[a][b]/10==0)cout<<"    "<<dt[a][b];
				else if(dt[a][b]/100==0)cout<<"   "<<dt[a][b];
				else if(dt[a][b]/1000==0)cout<<"  "<<dt[a][b];
				else if(dt[a][b]/10000==0)cout<<" "<<dt[a][b];
				else if(dt[a][b]/100000==0)cout<<dt[a][b];
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[100][100],d,f,g,h,i,j;
	while(1){
		scanf("%d",&a);
		if(a==0)	break;
		for(i=0;i<a;i++){
			for(j=0;j<a;j++){
				s[i][a]=0;
				s[a][i]=0;
				scanf("%d",&s[i][j]);
			}
		}
		s[a][a]=0;
		for(i=0;i<a;i++){
			for(j=0;j<a;j++){
				s[i][a]+=s[i][j];
				s[a][i]+=s[j][i];
			}
			s[a][a]+=s[i][a];
		}
		for(i=0;i<=a;i++){
			for(j=0;j<=a;j++){
				printf("%5d",s[i][j]);
	//			if(j!=a)	printf(" ");	
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int n;
    while(cin >> n){
        if(!n) break;

        int table[n+1][n+1];
        rep(i,n+1) table[i][n] = 0, table[n][i] = 0;

        rep(i,n)rep(j,n){
            cin >> table[i][j];
            table[i][n] += table[i][j];
            table[n][j] += table[i][j];
        }
        rep(i,n) table[n][n] += table[i][n];

        rep(i,n+1){
            rep(j,n){
                printf("%5d",table[i][j]);
            }
            printf("%5d\n",table[i][n]);
        }
    }

    return 0;
}

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

using namespace std;

int main()
{
	int n;
	int i,j;
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		int table[12][12]={0};
		
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				cin >> table[i][j] ;
			}
		}
		
		for(i=0;i<=n;i++)
		{
			for(j=0;j<=n;j++)
			{
				if(j!=n)
				{
					printf("%4d ",table[i][j]);
					table[i][n]+=table[i][j];
					table[n][j]+=table[i][j];
				}
				else
					printf("%4d",table[i][j]);
			}
			cout << endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)

int n, m;
int t[13][13];
int main(){
  while(cin >> n, n){
    rep(i,13)rep(j,13)t[i][j]=0;
    rep(i,n)rep(j,n){
      cin >> m;
      t[i][j] = m;
      t[n][j] += m;
      t[i][n] += m;
      t[n][n] += m;
    }
    rep(i,n+1){
      rep(j,n+1){
	printf("%5d",t[i][j]);
      }
      cout << endl;
    }
  }
  return 0;
}

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

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int dt[n+1][n+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>dt[i][j];
			}
		}
		for(int x=0;x<n+1;x++){
			dt[x][n]=0;
		}
		for(int y=0;y<n;y++){
			dt[n][y]=0;
		}
		for(int k=0;k<n;k++){
			for(int l=0;l<n;l++){
				dt[k][n]+=dt[k][l];
			}
		}
		for(int x=0;x<=n;x++){
			for(int y=0;y<n;y++){
				dt[n][x]+=dt[y][x];
			}
		}
		for(int a=0;a<=n;a++){
			for(int b=0;b<=n;b++){
				if(dt[a][b]/10==0)cout<<"    "<<dt[a][b];
				else if(dt[a][b]/100==0)cout<<"   "<<dt[a][b];
				else if(dt[a][b]/1000==0)cout<<"  "<<dt[a][b];
				else if(dt[a][b]/10000==0)cout<<" "<<dt[a][b];
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>

int main(){
  int n;
  while(std::cin>>n){
    if(!n)return 0;
    int v[11][11] = {0};
    for(int i=0;i<n;i++){
      std::string s;
      std::cin.get();
      getline(std::cin,s);
      std::stringstream ss(s);
      int num;
      for(int j=0;j<n;j++){
      ss>>num;
      v[j][i]=num;
      v[n][i]+=num;
      v[j][n]+=num;
      v[n][n]+=num;
      }
    }

    for(int y=0;y<=n;y++){
      for(int x=0;x<=n;x++){
        std::cout<<std::right<<std::setw(5)<<v[x][y];
      }
      std::cout<<std::endl;
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n,s[11];
	while(cin>>n,n){
		fill(s,s+10,0);
		for(int i=0;i<n;i++){
			int y=0,t;
			for(int j=0;j<n;j++){
				cin>>t;
				y+=t;
				s[j]+=t;
				cout<<t<<" ";
			}
			cout<<y<<endl;
		}
		int l=0;
		for(int i=0;i<n;i++){ cout<<s[i]<<" "; l+=s[i]; }
		cout<<l<<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/2)
#define PI (2*acos(0.0))
#define EPS (1e-8)

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(void){
  ios_base::sync_with_stdio(0);
  int n;
  while(cin >> n, n){
    vector< vector<int> > vec(n + 1, vector<int>(n + 1, 0));
    for(int i = 0; i < n; i++){
      int sum = 0;
      for(int j = 0; j < n; j++){
        cin >> vec[i][j];
        sum += vec[i][j];
      }
      vec[i][n] = sum;
    }

    for(int i = 0; i <= n; 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; i++){
      for(int j = 0; j <= n; j++){
        printf("%5d", vec[i][j]);
      }
      printf("\n");
    }
  }
  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;
				}
				if(j!=n) printf("%d ",x[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}