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<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];
				while(y<1000){
					printf(" ");
					y*=10;
				}
				printf("%d ",x[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

C++: 
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdio>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()


int main(void){
	int n;	
	while(cin>>n,n){	
		vvi ma(n+1,vi(n+1));
		rep(i,n){
			rep(j,n){
				cin>>ma[i][j];
				ma[n][j]+=ma[i][j];
				ma[i][n]+=ma[i][j];
			}
		}
		rep(i,n){
			ma[n][n]+=ma[i][n];
		}
		rep(i,n+1){
			rep(j,n+1){
				printf("%5d",ma[i][j]);
			}
			cout<<endl;
		}
	}
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int t[100][100];
  int n;
  while( cin >> n,n ){
  int c_sum[100],sum[100];
  for(int i = 0 ; i <= n ; i++){
    c_sum[i] = 0;
    sum[i] = 0;
  }
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      cin >> t[j][i];
      sum[i] += t[j][i]; 
      c_sum[j] += t[j][i];
    }
  }
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      printf("%5d",t[j][i]);
    }
    c_sum[n] += sum[i];
    printf("%5d\n",sum[i]);
  }
  for(int i = 0 ; i < n ; i++)printf("%5d",c_sum[i]);
  printf("%5d\n",c_sum[n]);
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n;
	while (cin >> n, n) {
		vector<vector<int>>v(n + 1, vector<int>(n + 1));
		rep(i, 0, n)rep(j, 0, n)cin >> v[i][j];
		rep(i, 0, n) {
			v[i][n] = accumulate(v[i].begin(), v[i].end(), 0);
		}
		rep(i, 0, n + 1) {
			int sum(0);
			rep(j, 0, n)sum += v[j][i];
			v[n][i] = sum;
		}

		rep(i, 0, n + 1) {
			rep(j, 0, n + 1) {
				printf("%5d", v[i][j]);
			}
			cout << endl;
		}
	}
	return 0;
}

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

int main(){
	int num[100][100] = {{0}};
	int n;
	int i,j;

	while(cin >> n, n){

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

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

		for(i = 0; i <= n; i++){
			for(j = 0; j <= n; j++){
				printf("%5d",num[i][j]);
				num[i][j] = 0; //テ・ツ按敕ヲツ慊淌・ツ個?
			}
			printf("\n");
		}

	}

}