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>
#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;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime> 

using namespace std;

int main(void){
	int n;
	int a,b;
	int hyo[11][11];
	while(1){
		cin >> n;
		if(n==0)break;
		for(b=0;b<=n;b++){
			for(a=0;a<=n;a++){
				hyo[a][b]=0;
			}
		}
		for(b=0;b<n;b++){
			for(a=0;a<n;a++){
				cin >> hyo[a][b];
				hyo[n][b]+=hyo[a][b];
			}
		}
		for(b=0;b<=n;b++){
			for(a=0;a<n;a++){
				hyo[b][n]+=hyo[b][a];
			}
		}
		for(b=0;b<=n;b++){
			for(a=0;a<=n;a++){
				cout << hyo[a][b] << ' ';
			}
			cout << endl;
		}
	}
	return 0;
}

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

int main() {
	int n;
	while (cin >> n, n) {
		int excel[11][11] = {};

		for (int i = 0;i < n;i++) {
			for (int j = 0;j < n;j++) {
				cin >> excel[i][j];
				excel[n][n] += excel[i][j] * 2;
			}
		}

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

		for (int i = 0;i < n;i++) {
			for (int j = 0;j < n;j++) {
				excel[n][i] += excel[j][i];
			}
		}
		for (int i = 0;i <= n;i++) {
			for (int j = 0;j <= n;j++) {
				printf("%5d", excel[i][j]);
				if (j == n) { cout << endl; }
			}
		}
	}
	return 0;
}