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;
int main(void)
{
	int n;
	while(cin>>n){
		int date[11][11]={0};
		if(!n) break;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				cin >> date[i][j];
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0; j<n; j++){
				date[i][n] += date[i][j];
			}
		}
		for(int i=0;i<=n;i++){
			for(int j=0; j<n; j++){
				date[n][i] += date[j][i];
			}
		}
		for(int i=0; i<=n; i++){
			for(int j=0; j<=n; j++){
				printf("%5d",date[i][j]);;
				if(j!=n) cout << " ";
			}
			cout << "\n";
		}
	}
	return 0;
}

C++: #include<iostream>
#include<iomanip>
using namespace std;
int main(void)
{
    int n,A=0,ober[10][10],side[10],lon=0;
    while(1){
        for(int i=0;i<12;i++)side[i]=0;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cin>>ober[i][j];
                side[j]+=ober[i][j];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<setw(6)<<ober[i][j]<<" ";
                A+=ober[i][j];
            }
            cout<<setw(6)<<A<<"\n";
            lon+=A;
            A=0;
        }
        for(int i=0;i<n;i++)cout<<setw(6)<<side[i]<<" ";
        cout<<setw(6)<<lon<<"\n";
        lon=0;
    }
}

C++: #include <stdio.h>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long Int;

int main() {
    for (;;) {
        int n;
        scanf("%d", &n);
        if (n == 0) return 0;
        vector<vector<int> > a(n+1, vector<int>(n+1, 0));
        rep (i, n) rep (j, n) scanf("%d", &a[i][j]);
        rep (i, n) rep (j, n) a[n][i] += a[j][i];
        rep (i, n+1) rep (j, n) a[i][n] += a[i][j];
        rep (i, n+1) rep (j, n+1) printf("%5d%c", a[i][j], "\n "[j<n]);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
int main()
{
	while (1) {
		int sum = 0;
		int num;
		std::cin >> num;
		if (num == 0)break;
		std::vector<std::vector<int>>vec(num + 1, std::vector<int>(num + 1));
		for (int i = 0; i < num; ++i) {
			for (int j = 0; j < num; ++j) {
				std::cin >> vec[i][j];
			}
		}
		for (int i = 0; i < num; ++i) {
			for (int j = 0; j < num; ++j) {
				vec[num][i] += vec[j][i];
				sum += vec[j][i];
				vec[i][num] += vec[i][j];
			}
		}
		vec[num][num] = sum;
		for (int i = 0; i < num + 1; ++i) {
			for (int j = 0; j < num + 1; ++j) {
				if (j == num)std::cout << vec[i][j] << std::endl;
				else std::cout << vec[i][j] << " ";
			}
		}
	}
	return 0;
}

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

int main() {
	const int MAX_N = 10;
	int N;
	int table[MAX_N][MAX_N];
	int keta[MAX_N][MAX_N];
	int max_keta;
	int sum[MAX_N], retu;
	int res;

	while (1) {
		cin >> N;
		if (N == 0)break;
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				cin >> table[i][j];
			}
		}

		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				keta[i][j] = (int)log10(table[i][j]) + 1;
			}
		}

		for (int i = 0;i < N;i++) {
			sum[i] = 0;
			for (int j = 0;j < N;j++) {
				for (int k = 0;k < 5 - keta[i][j];k++) {
					cout << " ";
				}
				cout << table[i][j];
				sum[i] += table[i][j];
			}
			for (int k = 0;k < 5 - (log10(sum[i]) + 1);k++) {
				cout << " ";
			}
			cout << sum[i] << endl;
		}
		//last
		for (int j = 0;j < N;j++) {
			retu = 0;
			for (int i = 0;i < N;i++) {
				retu += table[i][j];
			}
			for (int k = 0;k < 5 - (log10(retu) + 1);k++) {
				cout << " ";
			}
			cout << retu;
		}
		res = 0;
		for (int i = 0;i < N;i++) {
			res += sum[i];
		}
		for (int k = 0;k < 5 - (log10(res) + 1);k++) {
			cout << " ";
		}
		cout << res << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int graph[128][128];
	int num;
	
	while(cin >> num)
	{
		if(!num) break;
		int count = 0;
		int all = 0, las[128];
		for(int i = 0; i < 128; i++)
			las[i] = 0;

		for(int i = 0; i < num; i++)
		{
			for(int j = 0; j < num; j++)
			{
				cin >> graph[i][j];
				count += graph[i][j];
				las[j]  += graph[i][j];
				all += graph[i][j];
				if(j == num - 1) 
				{
					graph[i][j+1] = count;
					count = 0;
				}
				if(i == num - 1)
				{
					graph[i+1][j] = las[j];
				}
				if(i == num - 1 && j == num - 1)
				{
					graph[i+1][j+1] = all;
				}
			}
		}

		for(int i = 0; i < num + 1; i++)
		{
			for(int j = 0; j < num + 1; j++)
			{
				printf("%5d ", graph[i][j]);
		//		if(j != num)
		//			printf(" ");
			}
			puts("");
		}

	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int mt[20][20];

int main() {
	int n;
	while(n=in()){
		int i,j;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				mt[i][j]=in();
			}
		}
		for(i=0;i<n;i++){
			int sum=0;
			for(j=0;j<n;j++){
				sum+=mt[i][j];
			}
			mt[i][n]=sum;
		}
		for(i=0;i<=n;i++){
			int sum=0;
			for(j=0;j<n;j++){
				sum+=mt[j][i];
			}
			mt[n][i]=sum;
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d",mt[i][j]);
			}
			cout<<endl;
		}
	}
	return 0;
}