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 "bits/stdc++.h"
using namespace std;

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

		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<stdio.h>

int main(){
  while(1){
    int i,j,n;
    int a[10][10];
    scanf("%d", &n);
    if(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++){
	int m=0;
	for(j=0;j<n;j++){
	  m+=a[i][j];
	  printf("%5d", a[i][j]);
	}
	printf("%5d\n", m);
      }
      int k=0;
      for(j=0;j<n;j++){
	int l=0;
	for(i=0;i<n;i++){
	  l+=a[i][j];
	}
	printf("%5d", l);
	k+=l;
      }
      printf("%5d\n", k);
    }

    else
      break;
  }
  return 0;
}

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

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

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

int main(){
	
	int n ;
	
	while(1){
		cin >> n ;
		if( n==0 ) break ;
		
		int m[11][11] = {} ;
		
		for( int i=0 ; i<n ; i++ ){
			for( int j=0 ; j<n ; j++ ){
				cin >> m[i][j] ;
				m[i][n] += m[i][j] ;
			}
		}
		
		for( int j=0 ; j<n ; j++ ){
			for( int i=0 ; i<n ; i++ ){
				m[n][j] += m[i][j] ;
			}
		}
		
		for( int i=0 ; i<n ; i++ ){
			m[n][n] += m[n][i] ;
		}
		
		for( int i=0 ; i<=n ; i++ ){
			for( int j=0 ; j<=n ; j++ ){
				if( m[i][j] < 100 ) cout << ' ' ;
				cout << "  " << m[i][j] ;
			}
			cout << endl ;
		}
	}
	
return 0 ;
}

C++: #include<cstdio>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#define LL long long
using namespace std;
int main(void)
{
	LL n,dist[114][114],i,j,k,sum;
	while(1) {
		cin>>n;
		if(!n)break;
		for(i=0;i<n;i++) {
			sum=0;
			for(j=0;j<n;j++) {
				cin>>dist[i][j];
				sum+=dist[i][j];
			}
			dist[i][n]=sum;
		}
		for(i=0;i<=n;i++) {
			sum=0;
			for(j=0;j<n;j++) {
				sum+=dist[j][i];
			}
			dist[n][i]=sum;
		}
		for(i=0;i<=n;i++) {
			for(j=0;j<=n;j++) {
				printf("%5d",dist[i][j]);
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <cstdio>

using namespace std;

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

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n;
    while(1){
        cin>>n;
        if(n==0)return 0;
        vector<vector<int>> v(n+1,vector<int>(n+1,0));
        
        rep(i,0,n){
            int sum=0;
            rep(j,0,n){
                cin>>v[i][j];
                sum+=v[i][j];
            }
            v[i][n]=sum;
        }
        
        rep(j,0,n+1){
            int sum=0;
            rep(i,0,n){
                sum+=v[i][j];
            }
            v[n][j]=sum;
        }
        
        rep(i,0,n+1){
            rep(j,0,n+1){
                if(j==0)printf("%5d",v[i][j]);
                else printf(" %5d",v[i][j]);
            }
            cout<<endl;
        }
        
        
    }
    return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>
#include <memory>
#include <iomanip>

int main(int argc, char* argv[])
{
    while (true) {
        std::string line;
        std::stringstream buffer;
        getline(std::cin, line);
        buffer << line;
        size_t length = 0;
        buffer >> length;
        if (length == 0) break;
        int *total = new int[length + 1];
        size_t width = length + 1;
        memset(total, 0, sizeof(int) * width);
        for (size_t i = 0; i < length; ++i) {
            getline(std::cin, line);
            std::istringstream s(line);
            std::string element;
            int sum = 0;
            for (size_t n = 0; n < length; ++n) {
               getline(s, element, ' ');
               std::stringstream tmp;
                int val = 0;
                tmp << element;
                tmp >> val;
                sum += val;
                total[n] += val;
                std::cout << std::setw(5) << val;
            }
            std::cout << std::setw(5) << sum << std::endl;
            total[length] += sum;
        }
        for (size_t i = 0; i < width; ++i) {
            std::cout << std::setw(5) << total[i];
        }
        std::cout << std::endl;
        delete[] total;
    }
    return 0;
}