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<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(5)<<ober[i][j];
                A+=ober[i][j];
            }
            cout<<setw(5)<<A<<"\n";
            lon+=A;
            A=0;
        }
        for(int i=0;i<n;i++)cout<<setw(5)<<side[i];
        cout<<setw(5)<<lon<<"\n";
        lon=0;
    }
}

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

int n;
int field[1000][1000];
int total;

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    total = 0;
    for (int i=0; i<n; i++) {
      for (int j=0; j<n; j++) {
        scanf("%d", &field[i][j]);
        total += field[i][j];
      }
    }

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

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

    for (int i=0; i<n+1; i++) {
      printf("%4d", field[i][0]);
      for (int j=1; j<n+1; j++) {
        printf(" %4d", field[i][j]);
      }
      puts("");
    }
  }
}

C++: #include <stdio.h>
 
int main(void)
{
    int a[11][11];
    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]);
 
        a[n][n] = 0;
        for (i = 0; i < n; i++)
        {
            a[i][n] = 0;
            for (j = 0; j < n; j++)
                a[i][n] += a[i][j];
            a[n][n] += a[i][n];
        }
 
        for (j = 0; j < n; j++)
        {
            a[n][j] = 0;
            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>
#include <iomanip>
#include <vector>
using namespace std;

int main() {
  int n, sum, a;
  vector<int> v;

  while (cin >> n && n) {
    v.resize(n);
    for (int i=0; i<n; i++) v[i] = 0;
    for (int i=0; i<n; i++) {
      sum = 0;
      for (int j=0; j<n; j++) {
        cin >> a;
        cout << setw(5) << a;
        v[j] += a;
        sum += a;
      }
      cout << setw(5) << sum << endl;
    }
    sum = 0;
    for (int i=0; i<n; i++) {
      sum += v[i];
      cout << setw(5) << v[i];
    }
    cout << setw(5) << sum << endl;
  }

  return 0;
}

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

int main(){
	int n;
	int area[11][11];
	while(cin >> n){
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> area[i][j];
			}
		}
		for(int i = 0; i < n; i++){
			int count = 0;
			for(int j = 0; j < n; j++){
				count += area[i][j];
			}
			area[i][n] = count;
		}
		for(int j = 0; j <= n; j++){
			int count = 0;
			for(int i = 0; i < n; i++){
				count += area[i][j];
			}
			area[n][j] = count;
		}
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				cout << setw(5) << area[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
	int cell[11][11], n;

	while (cin >> n, n){
		for (int i = 0; i < 11; i++){
			for (int j = 0; j < 11; j++){
				cell[i][j] = 0;
			}
		}

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

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

C++: #include<stdio.h>
int main(void)
{
	int n;
	int i,j;
	int data[11][11];
	
	scanf("%d",&n);
	while(n!=0){

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

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

int main(){
  int n;
  while(std::cin>>n){
    if(!n)return 0;
    int v[11][11] = {0};
    std::cin.get();
    for(int i=0;i<n;i++){
      std::string s;
      getline(std::cin,s);
      std::stringstream ss(s);
      int num;
      for(int j=0;j<n;j++){
      ss>>num;
      v[j][i]=num;
      v[n][i]+=num;
      v[j][n]+=num;
      v[n][n]+=num;
      }
    }

    for(int y=0;y<=n;y++){
      for(int x=0;x<=n;x++){
        std::cout<<std::right<<std::setw(5)<<v[x][y];
      }
      std::cout<<std::endl;
    }
  }
}

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

int hoge(int w);
int getKetasu(int n);

int main(){
	int w;
	
	while(1){
	 cin>>w;
	 if(w==0){break;}
	 hoge(w);
	}
	
	return 0;
}

int hoge(int w){	//?????£???????????????
	int t[100][100];
	int x,y,i;
	
	for(y=0;y<w;y++){
	 for(x=0;x<w;x++){
	  cin>>t[x][y];
	 }
	}
	
	for(y=0;y<w;y++){
	 t[w][y]=0;
	 for(x=0;x<w;x++){
	  t[w][y]+=t[x][y];
	 }
	}
	for(x=0;x<=w;x++){
	 t[x][w]=0;
	 for(y=0;y<w;y++){
	  t[x][w]+=t[x][y];
	 }
	}
	
	for(y=0;y<=w;y++){
	 for(x=0;x<=w;x++){
	  for(i=getKetasu(t[x][y]);i<5;i++){cout<<" ";}
	  cout<<t[x][y];
	 }
	 cout<<endl;
	}
	
	return 0;
}

int getKetasu(int n){	//?????°?????????
	if(n<10){
	 return 1;
	}else if(n<100){
	 return 2;
	}else if(n<1000){
	 return 3;
	}else{
	 return 4;
	}
}