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<iostream>
#include<cstring>
#include<numeric>

int d[11][11];

int main(){
  int n;
	while( std::cin>>n , n ){
		memset(d,0,sizeof(d));
		for( int i=0; i<n; ++i ){
		  for( int l=0; l<n; ++l ){
			  std::cin>> d[l][i];
			}
		}
		for(int i=0; i<=n; ++i){
			for(int l=0;l<=n; ++l){
			  if(l==n && i!=n){
					for( int m=0;m<n;++m )
						d[l][i]+=d[m][i];
					std::cout<<d[l][i]<<std::endl;
				}else{
					if(i==n)std::cout<<std::accumulate(d[l],d[l]+n,0)<<(l!=n?" ":"\n");
					else std::cout<<d[l][i]<<" ";
				}
			}
		}
	}
}

C++: #include <iostream>
using namespace std;
int main(void)
{
	int n;
	while(cin>>n){
		int date[11][11]={0};
		if(!n) break;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				cin >> date[i][j];
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0; j<n; j++){
				date[i][n] += date[i][j];
			}
		}
		for(int i=0;i<=n;i++){
			for(int j=0; j<n; j++){
				date[n][i] += date[j][i];
			}
		}
		for(int i=0; i<=n; i++){
			for(int j=0; j<=n; j++){
				printf("%5d",date[i][j]);
			}
			cout << "\n";
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
	int N;
	while(cin>>N,N){
		int chart[11][11]={};
		for(int i=0;i<N;i++)for(int j=0;j<N;j++) cin>>chart[i][j];
		for(int i=0;i<=N;i++){
			int sumW=0,sumH=0;
			for(int j=0;j<N;j++){
				sumW += chart[i][j];
				sumH += chart[j][i];
			}
			chart[i][N] = sumW;
			chart[N][i] = sumH;
		}
		for(int i=0;i<=N;i++){
			for(int j=0;j<=N;j++){
				printf("%5d",chart[i][j]);
			}puts("");
		}
	}
    return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<set>
int elem[10][10];
using namespace std;

int main() {
	int n; 
	while(cin >> n, n != 0){
		int allsum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> elem[i][j];
				allsum += elem[i][j];
			}
		}
		elem[n][n] = allsum;
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += elem[i][j];
			}
			elem[i][n] = sum;
		}
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += elem[j][i];
			}
			elem[n][i] = sum;
		}
		
		for(int i=0; i<=n; i++){
			for (int j = 0; j <= n; j++) {
				cout << elem[i][j] << endl;
			}
		}
	}
	return 0;
}

C++: #include <stdio.h>
//#include <math.h>
using namespace std;

int log10(int n) {
	int keta = 0;
	while (n > 0) {
		n /= 10;
		keta++;
	}
	return keta;
}

int main() {
	const int MAX_N = 20;
	int N;
	int table[MAX_N][MAX_N];

	while (1) {
		for (int i = 0;i < MAX_N;i++) {
			for (int j = 0;j < MAX_N;j++) {
				table[i][j] = 0;
			}
		}
		scanf("%d", &N);
		if (!N)break;
		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][j] += table[i][j];
				table[N][N] += table[i][j];
			}
		}

		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				for (int k = 0;k < 5-log10(table[i][j]);k++) {
					printf(" ");
				}
				printf("%d", table[i][j]);
			}
			printf("\n");
		}
	}
printf("\n");

	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

int main()
{
  int n;
  while (cin >> n, n){
    int table[n][n], x[n], y[n], sum = 0;
    REP(i, n){
      REP(j, n) cin >> table[i][j];
      x[i] = y[i] = 0;
    }
    REP(i, n){
      cout << setw(5) << right << table[i][0];
      x[i] = table[i][0];
      FOR(j, 1, n){
        cout << setw(5) << right << table[i][j];
        x[i] += table[i][j];
      }
      cout << setw(5) << right << x[i] << endl;
    }
    REP(i, n){
      REP(j, n) y[i] += table[j][i];
    }
    cout << setw(5) << right << y[0];
    FOR(i, 1, n) cout << setw(5) << right << y[i];
    REP(i, n) sum += x[i];
    cout << setw(5) << right << sum << endl;
  }
}

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

int main(){
    int n,m;
    vector<vector<int> >vec;
    while(cin>>n,n){
        for(int i=0;i<n;i++){
            vector<int>v;
            for(int j=0;j<n;j++){
                cin>>m;
                v.push_back(m);
            }
            vec.push_back(v);
        }
        for(int i=0;i<n;i++){
            int s=0;
            for(int j=0;j<n;j++)
                s+=vec[i][j];
            vec[i].push_back(s);
        }
        vector<int>v;
        for(int i=0;i<n+1;i++){
            int s=0;
            for(int j=0;j<n;j++)
                s+=vec[j][i];
            v.push_back(s);
        }
        vec.push_back(v);
        for(int i=0;i<n+1;i++){
            for(int j=0;j<n+1;j++)
                cout<< setfill (' ') << setw (5)<<vec[i][j];
            cout<<endl;
        }
    }
}

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

using namespace std;


int main(void) {
    int n;
    while (scanf("%d", &n), n) {
        int a[110][110] = {};
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                scanf("%d", &a[i][j]);
        
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                a[i][n] += a[i][j];
        
        for (int j = 0; j <= n; j++)
            for (int i = 0; i < n; i++)
                a[n][j] += a[i][j];
        
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++)
                printf("%5d", a[i][j]);
            puts("");
        }
    }

    return 0;
}

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

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int dt[n+1][n+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>dt[i][j];
			}
		}
		for(int x=0;x<n+1;x++){
			dt[x][n]=0;
		}
		for(int y=0;y<n;y++){
			dt[n][y]=0;
		}
		for(int k=0;k<n;k++){
			for(int l=0;l<n;l++){
				dt[k][n]+=dt[k][l];
			}
		}
		for(int x=0;x<=n;x++){
			for(int y=0;y<n;y++){
				dt[n][x]+=dt[y][x];
			}
		}
		for(int a=0;a<=n;a++){
			for(int b=0;b<=n;b++){
				if(dt[a][b]/10==0)cout<<"    "<<dt[a][b];
				else if(dt[a][b]/100==0)cout<<"   "<<dt[a][b];
				else if(dt[a][b]/1000==0)cout<<"  "<<dt[a][b];
			}
			cout<<endl;
		}
	}
	return 0;
}