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 <cstring>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
 
int ary[10][10];
 
int main() {
        while(1) {
                static int n;
                memset(ary, 0, sizeof(ary));
                scanf(" %d", &n);
                if(!n)
                        break;
                for(int y = 0; y < n; y++) {
                        for(int x = 0; x < n; x++) {
                                static int t;
                                scanf(" %d", &t);
                                ary[y][x] = t;
                        }
                }
                vector<int> width;
                vector<int> height;
                for(int i = 0; i < n; i++) {
                        int sum = 0;
                        for(int j = 0; j < n; j++) {
                                sum += ary[i][j];
                        }
                        width.push_back(sum);
                }
                for(int i = 0; i < n; i++) {
                        int sum = 0;
                        for(int j = 0; j < n; j++) {
                                sum += ary[j][i];
                        }
                        height.push_back(sum);
                }
                int result = accumulate(height.begin(), height.end(), 0);
                
                for(int y = 0; y < n; y++) {
                        for(int x = 0; x < n; x++) {
                                printf("%5d", ary[y][x]);                       
                        }
                        printf("%5d\n", width[y]);
                }
                for(int i = 0; i < n; i++)
                        printf("%5d", height[i]);
                printf("%5d\n", result);
        }
        return 0;
}

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

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

	while (1) {
		for (int i = 0;i < MAX_N;i++) {
			for (int j = 0;j < MAX_N;j++) {
				table[i][j] = 0;
			}
		}
		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;
				table[i][N] += table[i][j];
				table[N][j] += table[i][j];
				table[N][N] += table[i][j];
			}
		}

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

	return 0;
}

C++: #include<stdio.h>
int d[10][10];
int t[10][10];
int n;
int i,j;
int res;

int main(){
	while(1){
	scanf("%d",&n);
	if(n==0)return 0;
	for(i=0;i<n;i++)for(j=0;j<n;j++){
		scanf("%d",&d[i][j]);
		t[i][j]=0;
	}
	for(i=0;i<n;i++){
		res=0;
		for(j=0;j<n;j++){
			res+=d[i][j];
			printf("%-5d ",d[i][j]);
		}
		printf("%-5d\n",res);
	}
	for(i=0;i<n;i++){
		res=0;
		for(j=0;j<n;j++){
			res+=d[j][i];
		}
		printf("%-5d ",res);
	}
	res=0;
	for(i=0;i<n;i++)for(j=0;j<n;j++){
		res+=d[i][j];
	}
	printf("%-5d\n",res);
	}
}

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

using namespace std;

int main()
{
    int data[10][10];
    int n;

    while (cin >> n, n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> data[i][j];
            }
        }
        int ans;
        for (int i = 0; i < n; i++) {
            ans = 0;
            for (int j = 0; j < n; j++) {
                printf("%5d", data[i][j]);
                ans += data[i][j];
            }
            printf("%5d\n", ans);
        }
        int s = 0;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += data[j][i];
            }
            printf("%5d", sum);
            s += sum;
        }
        printf("%5d\n", s);
    }
    return 0;
}

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

using namespace std;

int matrix[11][11];

int main()
{
	int n,sum;
	
	for(;;)
	{
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cin>>matrix[i][j];
			}
		}

		for(int i=0;i<n;i++)
		{
			sum=0;
			for(int j=0;j<n;j++)
			{
				sum+=matrix[i][j];
			}
			matrix[i][n]=sum;
		}
		for(int j=0;j<n;j++)
		{
			sum=0;
			for(int i=0;i<n;i++)
			{
				sum+=matrix[i][j];
			}
			matrix[n][j]=sum;
		}
		sum=0;
		for(int i=0;i<n;i++)
		{
			sum+=matrix[i][n];
		}
		matrix[n][n]=sum;
		
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=n;j++)
			{
				if(j>0)cout<<' ';
				cout<<setfill(' ')<<setw(5)<<right<<matrix[i][j];
			}
			cout<<endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int data[150][150] = { 0 };

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

		}
		for (int i = 0;i < n+1;i++) {
			for (int j = 0;j < n+1;j++) {
				cout << data[i][j]<<" ";
			}
			cout << endl;
		}
		

	}
	return 0;

}

C++: #include <stdio.h>

int main(void)
{
	int a[1000][1000] = {0};
	int n, i, j;

	scanf("%d", &n);
	while (n != 0)
	{
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				scanf("%d", &a[i][j]);

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

		for (j = 0; j < n; j++)
			for (i = 0; i < n; i++)
				a[n][j] += a[i][j];

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

	return 0;
}

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

int main(){
	int n;
	do	{
		int** Mat;
		cin >> n;
		if (n == 0){
			break;
		}
		Mat = new int*[n];
		for (int i = 0; i < n; i++){
			Mat[i] = new int[n];
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> Mat[i][j];
			}
		}

		int sumrow;
		int* sumcol;
		sumcol = new int[n]();
		int sum = 0;

		for (int i = 0; i < n; i++){
			sumrow = 0;
			for (int j = 0; j < n; j++){
				cout.width(5);
				cout << Mat[i][j];
				sumrow += Mat[i][j];
				sumcol[j] += Mat[i][j];
			}
			cout.width(5);
			cout << sumrow << endl;
		}
		for (int j = 0; j < n; j++){
			cout.width(5);
			cout << sumcol[j];
			sum += sumcol[j];
		}
		delete[] sumcol;
		cout.width(5);
		cout << sum << endl;



		//行列delete
		for (int i = 0; i < n; i++){
			delete[] Mat[i];
		}
		delete[] Mat;
	} while (n != 0);

}