Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}

		a := make([][]int, n+1)
		for i := 0; i < n; i++ {
			sum := 0
			stdin.Scan()
			a[i] = make([]int, n+1)
			str := strings.Split(stdin.Text(), " ")
			for j := 0; j < n; j++ {
				a[i][j], _ = strconv.Atoi(str[j])
				sum += a[i][j]
				fmt.Printf("%5d", a[i][j])
			}
			a[i][n] = sum
			fmt.Printf("%5d\n", a[i][n])
		}
		a[n] = make([]int, n+1)
		for i := 0; i <= n; i++ {
			sum := 0
			for j := 0; j < n; j++ {
				sum += a[j][i]
			}
			a[n][i] = sum
			fmt.Printf("%5d", a[n][i])
		}
		fmt.Println()
	}
}

C++: #include <cstdio>

int main(){
  int i,j,n,a[10][10],b[10],c[10],sum;
  while(1){

    scanf("%d",&n);
    if(n == 0) break;
    sum = 0;

    for(i=0;i<n;i++){
      b[i] = 0;
      for(j=0;j<n;j++){
	scanf("%d",&a[i][j]);
	b[i] += a[i][j];
	sum += a[i][j];
      }
    }
    for(i=0;i<n;i++){
      c[i] = 0;
      for(j=0;j<n;j++){
	c[i] += a[j][i];
      }
    }

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

  }
  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];
			sum += t[j][i];
		}
		t[i][i] = sum;
		for(i = 0;i < n + 1;i++){
			for(j = 0;j < n + 1;j++){
				printf("%d",t[i][j]);
				if(j != n) printf(" ");
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include<iostream>


using namespace std;


int main(){
	int a[10][10];
	int d, i, j, k, temp,sum=0;

	while (1){
		cin >> d;
		if (d == 0){
			return 0;
		}

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

		for (i = 0, j = 0; i < d; i++){
			for (j = 0; j < d; j++){
				cout.width(5);
				cout << a[i][j];
			}
			temp = 0;
			for (k = 0; k < d; k++){
				temp += a[i][k];
			}
			cout.width(5);
			cout << temp << endl;
			sum += temp;
		}
			
		

		for (j = 0; j < d; j++){
			temp = 0;
			for (k = 0; k < d; k++){
				temp += a[k][j];
			}
			cout.width(5);
			cout << temp;
			sum += temp;

		}



		cout.width(5);
		cout << sum/2 << endl;
		sum = 0;
	}
}

C++: //#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int a[15][15];
signed main(void)
{
  while(true) {
  int n;
  cin >> n;
  if(!n) break;
  REP(i, n) REP(j, n) cin >> a[i][j];

  REP(i, n) {
    int sum = 0;
    REP(j, n) {
      sum += a[i][j];
      printf("%5d", a[i][j]);
    }
    printf("%5d\n", sum);
  }
  int ret = 0;
  REP(i, n) {
    int sum = 0;
    REP(j, n) {
      sum += a[j][i];
    }
    ret += sum;
    printf("%5d", sum);
  }
  printf("%5d\n", ret);
}

  return 0;
}

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

int main(){
	int n;
	while(cin >> n){
		if(n == 0) break;
		else{
			int data[n+2][n+2] = {0};

			for (int i = 0; i < n+2; ++i){
				for(int j = 0; j < n+2; j++){					
				data[i][j] = 0;
				}
			}
			
			for (int i = 0; i < n; ++i){
				for(int j = 0; j < n; j++){					
				cin >> data[i][j];
				}
			}
			for (int i = 0; i < n; ++i){
				for(int j = 0; j < n; j++){	
					data[i][n] += data[i][j];
				}
			}
			for (int i = 0; i < n+1; ++i){
				for(int j = 0; j < n; j++){	
					data[n][i] += data[j][i];
				}
			}
			for (int i = 0; i < n+1; ++i){
				for(int j = 0; j < n+1; j++){
					cout << data[i][j];
					if (j != n) cout<<" ";
				}
				cout << endl;
			}
				
		}
	}
	return 0;
}

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>


using namespace std;


int main(){
	int a[10][10];
	int d, i, j, k, temp,sum=0;

	while (1){
		cin >> d;
		if (d == 0){
			return 0;
		}

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

		for (i = 0, j = 0; i < d; i++){
			for (j = 0; j < d; j++){
				cout.width(5);
				cout << a[i][j];
			}
			temp = 0;
			for (k = 0; k < d; k++){
				temp += a[i][k];
			}
			cout.width(5);
			cout << temp << endl;
			sum += temp;
		}
			
		

		for (j = 0; j < d; j++){
			temp = 0;
			for (k = 0; k < d; k++){
				temp += a[k][j];
			}
			cout.width(5);
			cout << temp;
			sum += temp;

		}



		cout.width(5);
		cout << sum/2 << endl;
		sum = 0;
	}
}

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

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

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

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;

#define REP(i, m, n) for (int i = static_cast<int>(m); i < static_cast<int>(n); ++i)

int main()
{
    
    

    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) break;
        
        VVI vvi;

        REP(i, 0, n) {
            vvi.push_back( vector<int>() );
            int sum = 0;
            
            REP(j, 0, n) {
                int in;
                std::cin >> in;
                vvi[i].push_back(in);
                sum += in;
            }
            vvi[i].push_back(sum);
        }

        vvi.push_back( vector<int>() );
        REP(i, 0, n + 1) {
            int sum = 0;
            
            REP(j, 0, n) {
                sum += vvi[j][i];
            }
            
            vvi[n].push_back(sum);
        }
        
        std::cout << "hoge" << std::endl;
        REP(i, 0, vvi.size()) {
            REP(j, 0, vvi[i].size()) {
                std::cout << std::setw(5) << vvi[i][j];
            }
            std::cout << std::endl;
        }
    }
    return 0;
}