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>
#include <cstring>
#include <cstdio>
using namespace std;

int t[12][12];

int main(){
  int n;

  while(cin >> n, n){
    //ツ配ツ療アツづー0ツづ?渉可甘コツ可サツつオツづ?つィツつュ
    memset(t, 0, sizeof(t));

    //ツ禿シツ療債つキツづゥツづつつ「ツづ?づ? ツ債?計ツづ可堕ォツつオツつアツづ敖づ?行ツつ、
    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][j];
      }
    }

    //ツ出ツ療?
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
        printf("%5d", t[i][j]);
      }
      cout << endl;
    }
  }
}

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

int main(void){
     int n;
     int ary[11][11];
     while(cin >> n,n){
	  for(int i=0;i<n;i++){
	       for(int j=0;j<n;j++){
		    ary[i][j]=0;
	       }
	  }
	  for(int i=0;i<n;i++){
	       for(int j=0;j<n;j++){
		    cin >> ary[i][j];
		    ary[i][n] += ary[i][j];
		    ary[n][j] += ary[i][j];
		    ary[n][n] += ary[i][j];
	       }
	  }
	  for(int i=0;i<=n;i++){
	       for(int j=0;j<=n;j++){
		    printf("%5d",ary[i][j]);
	       }
	       cout << endl;
	  }
     }
     return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,data[11][11];
  while(1){
    for(int i=0;i<11;i++){
      for(int j=0;j<11;j++){
	data[i][j]=0;
      }
    }
    cin>>n;
    if(n==0){break;}
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>data[i][j];
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	data[i][n]+=data[i][j];
	data[n][i]+=data[j][i];
	data[n][n]+=data[i][j];
      }
    }
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	printf("%5d",data[i][j]);
      }
       cout<<endl;
    }
  }
  return 0;
}

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

using namespace std;

int main(){
	int n[127], tn=0,ni=0,all = 0, i = 0;
	int data[512][256];
	int tdata[256] = { 0 };
	
		//input
	while (1){
		cin >> n[ni];
		if (n[ni] == 0)break;
		tn += n[ni];
		ni++;

		for (; i < tn; i++){
			for (int j = 0; j < n[ni]; j++){
				cin >> data[i][j];
			}
		}
	}
	

	//output
	for (int k = 0; k < ni; k++){
		for (int i = 0; i < tn; i++, all = 0){
			for (int j = 0; j < n[k]; j++){
				printf(" %5d", data[i][j]);
				all += data[i][j];
				tdata[j] += data[i][j];
			}
			printf(" %5d\n", all);
		}

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

C++: #include<iostream>

int main(){
	int n;
	while(std::cin>>n,n){
		int data[5][5];
		memset(data,0,sizeof(data));
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				std::cin>>data[i][j];
				data[i][4]+=data[i][j];
				data[4][j]+=data[i][j];
				data[4][4]+=data[i][j];
			}
		}
		for(int i=0;i<5;i++){
			for(int j=0;j<5;j++){
				std::cout<<data[i][j]<<" ";
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n;
	short matrix[11][11];

	while(cin >> n, n)
	{
		for(int i=0; i < n; i++) matrix[n][i] = matrix[i][n] = 0;
		matrix[n][n] = 0;
		for(int y=0; y < n; y++) {
			for(int x=0; x < n; x++) {
				cin >> matrix[y][x];
				matrix[n][x] += matrix[y][x];
				matrix[y][n] += matrix[y][x];
				matrix[n][n] += matrix[y][x];
			}
		}
		int nn = n + 1;
		for(int y=0; y < nn; y++) {
			for(int x=0; x < nn; x++) {
				if(x == nn)
					printf("%5d", matrix[y][x]);
				else
					printf("%5d ", matrix[y][x]);
			}
			printf("\n");
		}
	}

	return 0;
}

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

int main(){
  int n;
  while(true){
    cin >> n;
    if(n==0)
      break;

    vector<vector<int> > mop;
    vector<int> mup; 
    mup.resize(n+1);
    for(int i=0; i<n; i++){
      vector<int> mip;
      int k, l=0;
      for(int j=0; j<n; j++){
	cin >> k;
	mip.push_back(k);
	l+=k;
	mup[j]+=k;
      }
      mip.push_back(l);
      mop.push_back(mip);
    }
    for(int i=0; i<n; i++){
      mup[n]+=mup[i];
      for(int j=0; j<n+1; j++){
	printf("%5d", mop[i][j]);
      }
      cout << endl;
    }
    for(int i=0; i<=n; i++)
      printf("%5d", mup[i]);
    cout << endl;
  }

  return 0;
}

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

int main(void)
{
  int n;
  int i, j;
  while(1){
    cin >> n;
    if(n == 0){
      break;
    }
    
    
    int array[11][11] = {};
    for(i = 0; i < n; i++){
      for(j = 0; j < n; j++){
	cin >> array[i][j];
	array[i][n] = array[i][n] + array[i][j];
	array[n][j] = array[n][j] + array[i][j];
	array[n][n] = array[n][n] + array[i][j];
      }
    }

    for(i = 0; i <= n; i++){
      for(j = 0; j <= n; j++){
	std::cout << std::right << std::setw(5) << array[i][j];
      }
      cout << endl;
    } 

  }

    
    
  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  int M[12][12];
  while(cin>>n,n){
    rep(i,n)rep(j,n)cin>>M[i][j];
    rep(i,n){
      int tmp=0;
      rep(j,n)tmp+=M[i][j];
      M[i][n]=tmp;
    }
    rep(i,n){
      int tmp=0;
      rep(j,n)tmp+=M[j][i];
      M[n][i]=tmp;
    }
    int tmp=0;
    rep(i,n)tmp+=M[n][i];
    M[n][n]=tmp;
    rep(i,n+1){
      rep(j,n+1){
        if(M[i][j]<100){
          cout<<"   "<<M[i][j];
        }else if(M[i][j]<1000){
          cout<<"  "<<M[i][j];
        }else if(M[i][j]<10000){
          cout<<' '<<M[i][j];
        }else{
          cout<<M[i][j];
        }
      }
      cout<<endl;
    }
  }
  return 0;
}

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

int Matrix[11][11];

int main(void){
  int n;
  while(cin >> n && n != 0){
    for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> Matrix[i][j];
    int s = 0;
    for(int i = 0; i < n; i++){
      int sumt = 0, sumy = 0;
      for(int j = 0; j < n; j++){
        sumt += Matrix[i][j];
        sumy += Matrix[j][i];
      }
      Matrix[i][n] = sumt;
      Matrix[n][i] = sumy;
      s += sumt + sumy;
    }
    Matrix[n][n] = s;
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
        printf("%5d", Matrix[j][i]);
      }
      cout << endl;
    }
  }
  return 0;
}