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<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=10000;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
const int MAX=100001;
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
ll keta(ll n){
    int d=0;
    while(n>0){
        n/=10;
        d++;
    }
    return d;
}
int main(){
    int n;
    while(cin>>n,n){
        int a[12][12]={};
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cin>>a[i][j];
                a[i][n]+=a[i][j];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                a[n][i]+=a[j][i];
            }
        }
        for(int i=0;i<n;i++){
            a[n][n]+=a[n][i];
        }
        cout<<endl;
        for(int i=0;i<=n;i++,cout<<endl){
            for(int j=0;j<=n;j++){
                printf("%5d",a[i][j]);
            }
        }
    }
	return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
	int n;
	int x[12][12];
	
	while (cin >> n){
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				cin >> x[i][j];
			}
		}
	}
	
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			x[i][n + 1] += x[i][j];
		}
	}
	for (int j = 1; j <= n; j++){
		for (int i = 1; i <= n; i++){
			x[n + 1][j] += x[i][j];
		}
	}
	for (int i = 1; i <= n + 1; i++){
		for (int j = 1; j <= n + 1; j++){
			cout << x[i][j] << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;

int main() {
	while (cin >> n) {
		if(!n)break;
		int data[n + 1][n + 1];
		for (int i = 0; i < n; ++i) {
			int tmp, sum;
			for (int j = 0; j < n; ++j) {
				cin >> tmp;
				data[i][j] = tmp;
				sum += tmp;
			}
			data[i][n] = sum;
		}int sump=0;
		for (int i = 0; i < n; ++i) {
			int summ = 0;
			for (int j = 0; j < n; ++j) {
				summ += data[j][i];
			}
			data[n][i] = summ;
			sump+=summ;
		}data[n][n]=sump;
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				//cout << " " << data[i][j];
				printf("%5d",data[i][j]);
			}
			cout<<endl;
			//printf("\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (int i = 0; i < 100; i++)
	{
		int n,a[100][100];
		cin >> n;
		if (n == 0)
		{
			break;
		}

		for (int j = 0; j < n; j++)
		{
			for (int k = 0; k < n; k++)
			{
				cin >> a[j][k];
			}
		}
		int co = 0;
		int coo = 0;

		for (int j = 0; j < n; j++)
		{
			for (int k = 0; k < n; k++)
			{
				co += a[j][k];
			}
			a[j][n] = co;
			co = 0;
		}

		for (int k = 0; k < n + 1; k++)
		{
			for (int j = 0; j < n; j++)
			{
				coo += a[j][k];
			}
			a[n][k] = coo;
			coo = 0;
		}

		for (int j = 0; j < n + 1; j++)
		{
			for (int k = 0; k < n + 1; k++)
			{
				cout << a[j][k];
				if (k != n)
				{
					cout << " ";
				}
			}
			cout << endl;
		}
	}
}

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

C++: #include <bits/stdc++.h>
using namespace std;
int n;
void solve(){
  int table[200][200] = { 0 };

  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      scanf("%d", &table[i][j]);
      table[n][j] += table[i][j];
      table[i][n] += table[i][j];
    }
  }
  for (int i = 0; i < n; i++){
    table[n][n] += table[i][n];
  }
  for (int i = 0; i < n + 1; i++){
    int j = 0;
    printf("%d", table[i][0]);
    for (j = 1; j < n + 1; j++){
      printf(" %d", table[i][j]);
    }
    printf("\n");
  }
}

int main(){
  while (scanf("%d", &n), n)solve();
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

int main(){
	int n;
	while(cin>>n,n){
		vector<vint> vv;
		initvv(vv,n+1,n+1);
		rep(i,n){
			rep(j,n){
				cin>>vv[i][j];
			}
		}
		rep(i,n){
			int S=0;
			rep(j,n){
				S+=vv[i][j];
			}
			vv[i][n]=S;
			// cout<<S<<endl;
		}
		rep(i,n+1){
			int S=0;
			// cout<<0<<endl;
			rep(j,n){
				S+=vv[j][i];
				// cout<<j<<endl;
			}
			vv[n][i]=S;
			// cout<<S<<endl;
		}
		rep(i,n+1){
			rep(j,n+1){
				printf("%5d",vv[i][j]);
			}
			cout<<endl;
		}
	}
	return 0;
}

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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector< vector<int> > data(n + 1, vector<int>(n + 1));
		int sum = 0;
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin >> data[i][j];
			}
			int row_sum = 0;
			for(int j = 0; j < n; ++j)
			{
				row_sum += data[i][j];
			}
			data[i][n] = row_sum;
			sum += row_sum;
		}
		data[n][n] = sum;
		for(int i = 0; i < n; ++i)
		{
			int column_sum = 0;
			for(int j = 0; j < n; ++j)
			{
				column_sum += data[j][i];
			}
			data[n][i] = column_sum;
		}
		for(int i = 0; i < n + 1; ++i)
		{
			for(int j = 0; j < n + 1; ++j)
			{
				printf("%5d", data[i][j]);
			}
			cout << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <cstdio>
int imap[10000][10000];

int main() {

    int n, t, sum;
    for(; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++) {
            sum = 0;
            for (int j = 0; j < n; j++) {
                scanf("%d", &t);
                sum+=t;
                imap[i][j] = t;
            }
            imap[i][n] = sum;
        }
        for (int i = 0; i <= n; i++) {
            sum = 0;
            for (int j = 0; j < n; j++) {
                sum+= imap[j][i];
            }
            imap[n][i] = sum;
        }

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