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

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

using namespace std;

int main(void){

  int n;
  int a[10][10];
  
  while( cin >> n , n ){
    
    for( int i = 0 ; i < n ; i++ )
      for( int j = 0 ; j < n ; j++ )
	cin >> a[i][j];
    
    for( int i = 0 ; i < n ; i++ ){
      for( int j = 0 ; j < n ; j++ ){
	printf("%5d", a[i][j]);
	
	if( j == n - 1 ){
	  int sum = 0;
	  for( int k = 0 ; k < n ; k++ ){
	    sum += a[i][k];
	  }
	  printf("%5d", sum);
	}
      }
      cout << endl;
    }
    
    for( int i = 0 ; i < n ; i++ ){
      int sum = 0;
      for( int j = 0 ; j < n ; j++ ){
	sum += a[j][i];
      }
      printf("%5d", sum);
    }
    
    int sum = 0;
    for( int i = 0 ; i < n ; i++ ){
      for( int j = 0 ; j < n ; j++ ){
	sum += a[i][j];
      }
    }
    printf("%5d", sum);
    cout << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;

        int tmp;
        int mat[11][11];

        for (int i = 0; i < 11; i++)
            for (int j = 0; j < 11; j++)
                mat[i][j] = 0;


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

        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                if (j == n && i != n)
                    mat[n][n] += mat[i][j];
                printf("%5d", mat[i][j]);
            }
            putchar('\n');
        }
    }
    
    return 0;
}

C++: #include <stdio.h>

int main(void){
	int matrix[100][100],i,j,dataset;
	scanf("%d",&dataset);
	while(dataset!=0){

		//init add total norm
		for(i=0;i<dataset;i++){
			matrix[dataset][i]=0;
			matrix[i][dataset]=0;
		}

		//input and calc
		for(i=0;i<dataset;i++){
			for(j=0;j<dataset;j++){
				scanf("%d",&matrix[i][j]);
				matrix[i][dataset]+=matrix[i][j];
			}
		}

		//calc
		for(j=0;j<dataset+1;j++){
			for(i=0;i<dataset;i++){
				matrix[dataset][j]+=matrix[i][j];
			}
		}

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

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,c;
  while(cin>>n,n){
    int a[n+1][n+1];
    rep(i,n){c=0;rep(j,n){
        cin>>a[i][j];
        c+=a[i][j];
      }
      a[i][n]=c;
    }
    rep(j,n){c=0;rep(i,n){
      c+=a[i][j];
    }
    a[n][j]=c;
  }
  rep(i,n+1){rep(j,n+1){cout<<a[i][j];}cout<<endl;}
  }
}

C++: #include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	int n,sum=0,sumy=0;
	while (1){
		sum = 0;
		sumy = 0;
		cin >> n;
		if (n == 0)break;
		int ma[101][101] = { 0 };
		for (int i = 0; i < n; i++){
			sum = 0;
			for (int i2 = 0; i2 < n; i2++){
				cin >> ma[i][i2];
				sum += ma[i][i2];

			}
			sumy += sum;
			ma[i][n] += sum;
		}
		ma[n][n] += sumy;
		for (int i = 0; i < n; i++){
			sum = 0;
			for (int i2 = 0; i2 < n; i2++){
				sum += ma[i2][i];
				sumy += sum;
			}
			ma[n][i] += sum;
		}
		n++;
		for (int i = 0; i < n; i++){
			for (int i2 = 0; i2 < n; i2++){
				printf("%5d", ma[i][i2]);
			}
			cout << endl;
		}
	}
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_N = 10;
int n;
int a[MAX_N+1][MAX_N+1];

int main()
{
  while((cin >> n) && n){
    rep(i, n+1) rep(j, n+1) a[i][j] = 0;
    rep(i, n)   rep(j, n)   cin >> a[i][j];

    rep(i, n)   rep(j, n)   a[n][j] += a[i][j];
    rep(i, n+1) rep(j, n)   a[i][n] += a[i][j];

    rep(i, n+1) rep(j, n+1) printf("%5d%s", a[i][j], (j==n ? "\n" : ""));
  }

  return 0;
}

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