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

int main() {
  int n;
  while (cin >> n) {
    if (n == 0) break;
    int mat[n+1][n+1];
    for (int i = 0; i < n; i++) {
      mat[i][n] = 0;
      for (int j = 0; j < n; j++) {
	cin >> mat[i][j];
	mat[i][n] += mat[i][j];
      }
    }
    for (int i = 0; i < n+1; i++) {
      mat[n][i] = 0;
      for (int j = 0; j < n; j++) {
	mat[n][i] += mat[j][i];
      }
    }
    for (int i = 0; i < n+1; i++) {
      for (int j = 0; j < n+1; j++) {
	cout << right << setw(5) << mat[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

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

using namespace std;

int main(){

	int N;
	while(cin>>N,N){
		vector<int> vi(N*N,0),vi2(N*2+1,0);
		for(int i=0;i<N;i++){
			int sum=0;
			for(int j=0;j<N;j++){
				int num;
				cin>>num;
				vi[i*N+j]=num;
				sum+=num;
			}
			vi2[i]=sum;
		}
		for(int i=0;i<N;i++){
			int sum=0;
			for(int j=0;j<N;j++){
				sum+=vi[i+j*N];
				printf("%5d",vi[i*N+j]);
			}
			printf("%5d\n",vi2[i]);
			vi2[N*2]+=vi2[i];
			vi2[N+i]=sum;
		}
		for(int i=0;i<=N;i++){
			printf("%5d",vi2[N+i]);
		}
		cout<<endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

#define MP make_pair<int,int>

int mp[25][21];

int main(){
  while(true){
    int n;
    cin>>n;
    if(!n)break;
    REP(i,n+1)REP(j,n+1)mp[i][j]=0;
    REP(i,n)REP(j,n)cin>>mp[i][j];
    REP(i,n)REP(j,n)mp[i][n] += mp[i][j];
    REP(i,n)REP(j,n+1)mp[n][j] += mp[i][j];
    REP(i,n+1){
      REP(j,n+1)printf("%5d",mp[i][j]);
      printf("\n");
    }
  }
  return 0;
}

C++: /*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return 0;
	}
#endif
	/*****変数置き場*****/
	int n;
	int matrix[11][11];
	/*****処理部*****/
	while(1){
		cin >> n;
		if(n==0)	break;
		for(int i=0;i<11;i++)
			for(int j=0;j<11;j++)
				matrix[i][j] = 0;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				cin >> matrix[i][j];
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				matrix[i][n] += matrix[i][j];
		for(int j=0;j<n;j++)
			for(int i=0;i<n;i++)
				matrix[n][j] += matrix[i][j];
		for(int i=0;i<n;i++)
			matrix[n][n] += matrix[i][n];
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				cout.width(5);
				cout << matrix[i][j];
			}
			cout << endl;
		}
	}

	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int n;
int t[11][11];
int main(){
  while(cin>>n){
    if(n==0)break;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>t[i][j];
      }
    }
    for(int j=0;j<n;j++){
      t[n][j]=0;
      for(int i=0;i<n;i++){
	t[n][j]+=t[i][j];
      }
    }
    for(int i=0;i<=n;i++){
      t[i][n]=0;
      for(int j=0;j<n;j++){
	t[i][n]+=t[i][j];
      }
    }

    for(int i=0;i<=n;i++){
      
      for(int j=0;j<=n;j++){

	printf("%5d",t[i][j]);
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include <stdio.h>
int main(){
	int n;
	while(1){
	    int l,r;
		int a[11][11];
		scanf("%d",&n);
		if(!n) break;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++) scanf("%d",&a[i][j]);
		}
		for(int i=0;i<n+1;i++){
			l=r=0;
			for(int j=0;j<n;j++){
				l+=a[i][j];
				r+=a[j][i];
			}
			a[i][n]=l;
			a[n][i]=r;
		}
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++) printf("%4d",a[i][j]);
			printf("\n");
		}
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;

int main(){
int N,num[11][11]={},x;
int a;
while(1)
{cin>>N;
if(N==0)break;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++)
{cin>>num[i][j];num[i][N]+=num[i][j];}
}
for(int i=0;i<N;i++)
num[N][N]+=num[i][N];
for(int i=0;i<N;i++)
	for(int j=0;j<N;j++)
num[N][i]+=num[j][i];

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++)
{
a =5-( (int)log10((double)(num[i][j]) )+ 1);
for(int k=0;k<a;k++)
{cout<<" ";}
cout<<num[i][j];}
cout<<endl;


}

for(int i=0;i<=10;i++){
for(int j=0;j<=10;j++){
num[i][j]=0;
}
}


}

return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv){
	int **array;
	int n;
	
	while(1){
		scanf("%d", &n);
		if(n == 0){
			break;
		}
		
		array = (int **)calloc(n+1, sizeof(int));
		for(int i = 0; i <= n; i++){
			array[i] = (int *)calloc(n+1, sizeof(int));
		}
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				scanf("%d", &array[i][j]);
				
				array[i][n] += array[i][j];
			}
		}
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j < n; j++){
				array[n][i] += array[j][i];
			}
			array[n][n] += array[n][i];
		}
		array[n][n] /= 4;
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%5d", array[i][j]);
			}
			printf("\n");
		}
		
		for(int i = 0; i <= n; i++){
			free(array[i]);
		}
		free(array);
	}
	
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <fstream>
#include <string.h>

#define X first
#define Y second
#define MP make_pair
typedef long long ll;
using namespace std;
const int MAX = 101;

template<class T, class U>
void convert(T &t, U &u){
	stringstream ss;
	ss << t;
	ss >> u;
}

int main(){
	int n;
	while(cin >> n && n != 0){
		vector<vector<int> > ans(n+1, vector<int>(n+1, 0));
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> ans[i][j];
				ans[i][n] += ans[i][j];
				ans[n][j] += ans[i][j];
			}
			ans[n][n] += ans[i][n];
		}

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

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

using namespace std;

int main()
{
	int n;
	
	while (scanf("%d", &n), n != 0){
		int t[11][11] = {0};
		
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> t[i][j];
				t[i][n] += t[i][j];
				t[n][j] += t[i][j];
			}
			t[n][n] += t[i][n];
		}
		for (int i = 0; i <= n; i++){
			for (int j = 0; j <= n; j++){
				printf("%5d", t[i][j]);
			}
			printf("\n");
		}
	}
	return (0);
}