Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		input := make([][]int, n+1, n+1)
		totalRow := make([]int, n+1, n+1)

		for i := 0; i < n; i++ {
			row := make([]int, n+1, n+1)
			scanner.Scan()

			row = numbers(scanner.Text())

			input[i] = row
			total(totalRow, row)
		}

		input[n] = totalRow

		for xk := range input {
			for yk, yv := range input[xk] {
				if yk == n {
					fmt.Printf("%5d\n", yv)
				} else {
					fmt.Printf("%5d", yv)
				}
			}
		}
	}
}

func total(sum, row []int) {
	for i := 0; i < len(row); i++ {
		sum[i] += row[i]
	}
}

func numbers(s string) []int {
	var n []int
	var sum int
	for _, f := range strings.Fields(s) {
		i, err := strconv.Atoi(f)
		if err == nil {
			n = append(n, i)
			sum += i
		}
	}
	n = append(n, sum)
	return n
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N;
	while (cin >> N, N) {
		int num[150][150] = { { 0 } };
		for (int i = 0;i<N;i++) {
			for (int j = 0;j<N;j++) {
				cin >> num[i][j];
				num[i][N] += num[i][j];
				num[N][j] += num[i][j];
				num[N][N] += num[i][j];
			}
		}
		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				if (num[i][j]<10) {
					for (int k = 0;k<4;k++)cout << " ";
				}
				else if (num[i][j]<100) {
					for (int k = 0;k<3;k++)cout << " ";
				}
				else if (num[i][j]<1000) {
					for (int k = 0;k<2;k++)cout << " ";
				}
				else if (num[i][j]<10000) {
					for (int k = 0;k<1;k++)cout << " ";
				}
				cout << num[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

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

int main(){
	int i,j,n,a[101][101];
	while(scanf("%d",&n)==1&&n){
		memset(a,0,sizeof(a));
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&a[i][j]);
				a[i][n] += a[i][j];
				a[n][j] += a[i][j];
				a[n][n] += a[i][j];
			}
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d",a[i][j]);
			}
			puts("");
		}
	}
	return 0;
}

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

using namespace std;

typedef unsigned long long ull;

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

int main(){
    int n;
    while(cin>>n, n){
        int h[10]={}, v[10]={};
        rep(i,n){
            int s=0;
            rep(j,n){
                cin>>h[j];
                printf("%5d",h[j]);
                s+=h[j];
                v[j]+=h[j];
            }
            printf("%5d\n",s);
        }
        int s=0;
        rep(i,n){
            printf("%5d",v[i]);
            s+=v[i];
        }
        printf("%5d\n",s);
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int n; cin >> n;
    do {
        int a[n+1][n+1];
        memset(a, 0, sizeof(a));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> a[i][j];
                a[i][n] += a[i][j];
                a[n][j] += a[i][j];
                a[n][n] += a[i][j];
            }
        }
        for (int i = 0; i < n+1; i++) {
            for (int j = 0; j < n+1; j++) {
                cout << right << setw(5) << a[i][j];
            }
            cout << endl;
        }
        cin >> n;
    } while (n != 0);
    return 0;
}

C++: #include <iostream>
#include <iomanip>
using namespace std;
int main(){
	while(1){
	int n; cin >> n ;
	if(!n) break;
	int num[10][10];
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++) cin >> num[i][j];
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=0;j<n;j++){
			sum+=num[i][j];
			if(j) cout << ' ' ;
			cout.width(5);
			cout << num[i][j] ;
		};
		cout.width(5);
	cout << ' ' << sum << '\n' ;
	};
	int* sum=new int[n]; int nsum=0;
	for(int i=0;i<n;i++){
		sum[i]=0;
		if(i) cout << ' ' ;
		for(int j=0;j<n;j++) sum[i]+=num[j][i];
		cout.width(5);
		cout << sum[i] ;
		nsum+=sum[i];
	};
	cout.width(5);
	cout << ' ' << nsum << '\n' ;
	};
}

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<vector>
#include<string>
#include<set>
int elem[10][10];
using namespace std;

int main() {
	int n; 
	while(cin >> n, n != 0){
		int allsum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> elem[i][j];
				allsum += elem[i][j];
			}
		}
		elem[n][n] = allsum;
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += elem[i][j];
			}
			elem[i][n] = sum;
		}
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += elem[j][i];
			}
			elem[n][i] = sum;
		}
		
		for(int i=0; i<=n; i++){
			for (int j = 0; j <= n; j++) {
				if (j == n) {
					cout << elem[i][j] << endl;
					break;
				}
				cout << elem[i][j] << " ";
			}
		}
	}
	return 0;
}

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

using namespace std;

int main(){
	int n,all=0;
	int data[120000];
	int tdata[120000] = { 0 };
	
	cin >> n;

	for (int i = 0; i < n; i++,all=0){
		for (int j = 0; j < n; j++){
			cin >> data[j];
			printf(" %d",data[j]);
			all += data[j];
			tdata[j] += data[j];
		}
		printf(" %d\n", all);
	}

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

	return 0;
}

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

int main(int argc, char const* argv[])
{
	int n{};
	std::cin >> n;
	while (n) {
		std::vector<int> table{};
		for (int i = 0; i < n * n; i++) {
			int d;
			std::cin >> d;
			table.push_back(d);
		}
		for (int i = 0; i < n; i++) {
			auto hsum = 0;
			for (int j = 0; j < n; j++) {
				auto current = table[i * n + j];
				hsum += current;
				std::cout << std::setw(5) << std::right << current ;
			}
			std::cout << std::setw(5) << std::right << hsum;
			std::cout << std::endl;
		}
		int sum{};
		for (int i = 0; i < n; i++) {
			auto vsum = 0;
			for (int j = 0; j < n; j++) {
				auto current = table[j * n + i];
				vsum += current;
			}
			std::cout << std::setw(5) << std::right << vsum;
			sum += vsum;
		}
		std::cout << std::setw(5) << std::right << sum;
		std::cout << std::endl;
		std::cin >> n;
	}

	return 0;
}