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 <iomanip>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    int n;
    while (std::cin >> n && n > 0) {
        std::cin.ignore();

        std::vector<int> vec;
        std::string s;
        for (int i = 0; i < n; i++) {
            std::getline(std::cin, s);

            std::stringstream ss(s);
            std::copy(std::istream_iterator<int>(ss), {},
                      std::back_inserter(vec));
        }

        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                std::cout << std::right << std::setw(5) << vec[n * i + j];
                sum += vec[n * i + j];
            }
            std::cout << std::right << std::setw(5) << sum << std::endl;
        }
        int total = 0;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) { sum += vec[n * j + i]; }
            std::cout << std::right << std::setw(5) << sum;
            total += sum;
        }
        std::cout << std::right << std::setw(5) << total << std::endl;
    }
}

C++: #include<stdio.h>
int main(void)
{
	int n,x[101][101],i,j,sum;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++) scanf("%d",&x[i][j]);
		}
		for(i=0;i<n;i++){
			sum=0;
			for(j=0;j<n;j++) sum+=x[j][i];
			x[n][i]=0;
			x[n][i]=sum;
		}
		for(i=0;i<=n;i++){
			sum=0;
			for(j=0;j<n;j++) sum+=x[i][j];
			x[i][n]=0;
			x[i][n]=sum;
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%d ",x[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <map> 
#include <sstream>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int n;
  while(cin>>n,n){
    vector<vector<int> > in(n+1,vector<int>(4,0));
    rep(i,n){
      rep(j,4){
	cin>>in[i][j];
	printf("%5d",in[i][j]);
	in[i][4] += in[i][j];
	in[n][j] += in[i][j];
      }
      printf("%5d\n",in[i][4]);
    }
    rep(j,4){
      printf("%5d",in[n][j]);
      in[n][4] += in[n][j];
    } 
    printf("%5d\n",in[n][4]);
  }

}

C++: 
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long lon
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)

using namespace std;

int main (void){
    
    int number;
    while(cin >> number,number)
    {
        int math[11][11] ={0};
        REP(i,number)
        {
            REP(j,number)
            cin >> math[i][j];
        }
        REP(i,number)
            REP(j,number)
        math[i][number] += math[i][j];
        REP(i,number)
            REP(j,number)
        math[number][i] += math[j][i];
        REP(i,number)
        REP(j,number)
        math[number][number]+= math[i][j];
        REP(j, number+1)
        REP(i,number+1){
            printf("%5d",math[j][i]);
            if(i == number || (j == number && i == number))
                cout << endl;
                 }
    }
    return 0;
    
  
}

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

int main(){
	int n;
	int matrix[100][100];
	while(cin >> n){
		if(n==0) return 0;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				cin >> matrix[i][j];
			}
		}
		int sumX[100],sumY[100],sum=0;		
		for(int i=0; i<n; i++){
			sumX[i]=0; sumY[i]=0;
			for(int j=0; j<n; j++){
				sumX[i] += matrix[j][i];
				sumY[i] += matrix[i][j];
			}
			sum+=sumX[i];
		}
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				printf("%5d",matrix[i][j]);
			}
			printf("%5d\n",sumY[i]);
		}
		for(int i=0; i<n; i++) printf("%5d",sumX[i]);
		printf("%5d\n",sum);
		
	}
}

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

using namespace std;

int main() {
    
    int n;
    cin >> n;
    
    int A[51][51] = {};
    
    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][n];
}

	for(int i=0;i<=n;i++) { 
    for(int j=0;j<=n;j++) {
    	
    	cout << setw(4)<< A[i][j] << " ";
    
	}
	cout << "\n";
}
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#define MAX_N 15
using namespace std;
int main(){
	int n,i,j;
	while(1){
		cin >> n;
		if(n==0)break;
		int a[MAX_N][MAX_N];
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				a[i][j]=0;
			}
		}


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

		int sum1=0,sum[MAX_N];
		for(i=0;i<n;i++){
			for(j=0;j<=n;j++){
				sum1+=a[i][j];
				if(j==n){
					a[i][j]=sum1;
					sum1=0;
				}
			}
		}

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


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

	}
	return 0;
}

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

int main(){
	int data_size;
	cin >> data_size;
	while (data_size){
		vector<vector<int>> data;
		vector<vector<int>> data_digit;
		data.resize((data_size + 1)*(data_size + 1));
		data_digit.resize((data_size + 1) * (data_size + 1));
		for (int i = 0; i < data_size; i++){
			data[i].resize(data_size + 1);
			data_digit[i].resize(data_size + 1);
			for (int j = 0; j < data_size; j++){
				cin >> data[i][j];
				int tmp = data[i][j];
				data_digit[i][j] = 0;
				while (tmp){
					tmp /= 10;
					data_digit[i][j]++;
				}
			}
		}
		data[data_size].resize(data_size + 1);
		data_digit[data_size].resize(data_size + 1);
		for (int i = 0; i < data_size; i++){
			int sum = 0;
			for (int j = 0; j < data_size; j++){
				sum += data[i][j];
			}
			data[i][data_size] = sum;
			int tmp = sum;
			data_digit[i][data_size] = 0;
			while (tmp){
				tmp /= 10;
				data_digit[i][data_size]++;
			}

		}
		for (int i = 0; i < data_size + 1; i++){
			int sum = 0;
			for (int j = 0; j < data_size; j++){
				sum += data[j][i];
			}
			data[data_size][i] = sum;
			int tmp = sum;
			data_digit[data_size][i] = 0;
			while (tmp){
				tmp /= 10;
				data_digit[data_size][i]++;
			}
		}

		for (int i = 0; i < data_size + 1; i++){
			for (int j = 0; j < data_size + 1; j++){
				for (int k = data_digit[i][j]; k < 5; k++){
					cout << " ";
				}
				cout << data[i][j];
			}
			cout << "\n";
		}
		cin >> data_size;
	}
	return 0;
}