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<vector>
int main(){
	while(1){
		int a;
		std::cin>>a;
		if(a==0)break;
		std::vector<std::vector<int> > vec(a+1,std::vector<int> (a+1));
		for(int i=0;i<a;i++){
			int b=0;
			for(int j=0;j<a;j++){
				std::cin>>vec[i][j];
				b+=vec[i][j];
			}
			vec[i][a]=b;
		}
		for(int i=0;i<a;i++){
			int c=0;
			for(int j=0;j<a;j++){
				c+=vec[j][i];
			}
			vec[a][i]=c;
		}
		int d=0;
		for(int i=0;i<a;i++){
			d+=vec[a][i];
		}
		vec[a][a]=d;
		for(int i=0;i<a+1;i++){
			for(int j=0;j<a+1;j++){
				if(j!=a)std::cout<<vec[i][j]<<" ";
				else std::cout<<vec[i][j];
			}
			std::cout<<std::endl;
		}
		std::cout<<std::endl;
	}

	return 0;
}

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

using namespace std;

int n;


int main(){
    while(cin>>n){
        if(n==0)break;
        int box[11][11]={0};
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                cin>>box[i][j];
            }
        }
        
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                box[i][n]+=box[i][j];
            }
        }
        
        for(int i=0; i<n; i++){
            for(int j=0; j<=n; j++){
                box[n][j]+=box[i][j];
            }
        }
        
        for(int i=0; i<=n; i++){
            for(int j=0; j<=n; j++){
                cout.width(5);
                cout<<box[i][j];
            }
            cout<<endl;
        }
        
    }
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
int in[11][11]={0};
int main(){
int n;
while(cin>>n,n){
rep(i,n){
int sum=0,j;
for(j=0;j<n;j++){
int tmp;
cin>>tmp;
sum+=tmp;
in[i][j]=tmp;
printf("%5d ",tmp);
}
in[i][j]=sum;
printf("%5d\n",sum);
}

rep(i,n+1){
int sum=0;
rep(j,n){
sum+=in[j][i];
}
if(i!=n)printf("%5d ",sum);
else printf("%5d\n",sum);
}
}
}

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

C++: #include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
    int n;
    while(cin>>n, n!=0) {
        int G[n+1][n+1] = {0};
        for(int i=0; i<n; ++i) {
            for(int j=0; j<n; ++j) {
                cin >> G[i][j];
                G[i][n]+=G[i][j];
                G[n][j]+=G[i][j];
                G[n][n]+=G[i][j];
            }
        }
        for(int i=0; i<n+1; ++i) {
            for(int j=0; j<n+1; ++j) {
                printf("%5d", G[i][j]);
            }
            cout << endl;
        }
    }
    return 0;
}

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

int main(){
	int n;
	while(std::cin>>n,n){
		int data[10][10];
		memset(data,0,sizeof(data));
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				std::cin>>data[i][j];
				data[i][n]+=data[i][j];
				data[n][j]+=data[i][j];
				data[n][n]+=data[i][j];
			}
		}
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++){
				std::cout<<std::setw(5)<<std::right<<data[i][j];
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	while(cin >> n,n){
		int data[10+1][10+1];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}

		int all_sum = 0;

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




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


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

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

using namespace std;

int main()
{
	int n, num[11][11];
	while (1) {
		if (cin >> n, !n) break;
		
		for (int i=0; i<11; i++) for (int j=0; j<11; j++) num[i][j] = 0;
		
		for (int i=0; i<n; i++) for (int j=0; j<n; j++) cin >> num[i][j];
		
		for (int i=0; i<10; i++)
			for (int j=0; j<10; j++) num[10][i] += num[j][i];
		
		for (int i=0; i<11; i++)
			for (int j=0; j<10; j++) num[i][10] += num[i][j];
		
		for (int i=0; i<11; i++) {
			for (int j=0; j<11; j++) {if ((i<n && j<n) || (i==10 && j<n) || (j==10 && i<n) || (j==10 && i==10)) {cout.width(5); cout << num[i][j];}}
			if ((i < n) || (i == 10))  cout << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main(){
	int n[127], tn=0,ni=0,all = 0, i = 0;
	int data[1024][10];
	int tdata[10] = { 0 };
	
		//input
	while (1){
		cin >> n[ni];
		if (n[ni] == 0)break;
		tn += n[ni];
		ni++;

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

	//output
	for (int k = 0; k < ni; k++){
		for (int i = 0; i < tn; i++, all = 0){
			for (int j = 0; j < n[k]; j++){
				printf(" %5d", data[i][j]);
				all += data[i][j];
				tdata[j] += data[i][j];
			}
			printf(" %5d\n", all);
		}

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

		for (int i = 0; i < n[k]; i++){
			tdata[i] = 0;
		}
		all = 0;
	}
	return 0;
}

C++: #include <cstdio>

int main(){
  int n;
  
  while(1){
    scanf("%d", &n);
    if(!n) break;
    
    int table[11][11] = {0};
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	scanf("%d", &table[i][j]);
      }
    }
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
	table[i][n] += table[i][j];
	table[n][i] += table[j][i];
      }
    }
    
    for(int i=0; i<n; i++)
      table[n][n] += table[n][i];
    
    for(int i=0; i<=n; i++){
      for(int j=0; j<n; j++)
	printf("%5d", table[i][j]);
      putchar('\n');
    }
  }
    
  return 0;
}