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>
using namespace std;

int main(){
	int n,i,j;
	while(cin >> n && n){
		int table[11][11] = {{0}};
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				cin >> table[i][j];
				table[i][n] += table[i][j];
				table[n][j] += table[i][j];
			}
			table[n][n] += table[i][n];
		}
		for(i = 0;i <= n;i++){
			for(j = 0;j <= n;j++){
				if(table[i][j] / 100 != 0) cout << "  ";
				else cout << "   ";
				cout << table[i][j];
			}
			cout << "\n";
		}
	}
	return 0;
}

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

int main(){
	
	int n,h,w;
	while(cin>>n){
		if(n!=0){
		int sw=0;
		vector< vector<int> >c(n+2,vector<int>(n+2));
		for(int i=0;i<n;i++){
				w=0;
			for(int j=0;j<n;j++){
				cin>>c[i][j];
				w+=c[i][j];
			}
			c[i][n]=w;
			sw+=w;
		}
		for(int i=0;i<n;i++){
			h=0;
			for(int j=0;j<n;j++){
			h+=c[j][i];
		}
			c[n][i]=h;
		}
		c[n][n]=sw;
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++)
			printf("%5d",c[i][j]);
			cout<<endl;
		}
		
		
	}
		else
			break;
	}
		
	
}

C++: #include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int n,all=0;
	int data[256];
	int tdata[256] = { 0 };
	
	cin >> n;

	for (int i = 0; i < n; i++,all=0){
		for (int j = 0; j < n; j++){
			cin >> data[j];
			printf(" %d",data[j]);
			all += data[j];
			tdata[j] += data[j];
		}
		printf(" %d\n", all);
	}

	all = 0;
	for (int i = 0; i < n; i++){
		printf(" %d", tdata[i]);
		all += tdata[i];
	}
	printf(" %d\n", all);

	return 0;
}

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

int main()
{
	while (1)
	{
		int a;
		cin >> a;
		if (a == 0)break;
		vector<int>tate(a+1);
		for (int b = 0; b < a; b++) 
		{
			vector<int>yoko(a);
			int s = 0;
			for (int c = 0; c < a; c++)
			{
				int d;
				cin >> d;
				yoko[c] = d;
				s +=d;
				tate[c] += d;
			}
			for (int k : yoko) {
				cout << setw(5) << k;
			}
			tate[a] += s;
			cout << setw(5) << s <<endl;
		}
		for (int k : tate) {
			cout << setw(5) << k;
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <math.h>
using namespace std;
int main() {
	int n, a[10][10] = {}, sum_h[11] = {}, sum_v[11] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			cout << a[i][j] << " ";
			sum_h[i] += a[i][j];
			sum_v[j] += a[i][j];
		}
		sum_v[n] += sum_h[i];
		cout << sum_h[i] << endl;
	}
	for (int i = 0; i < n; i++)
		cout << sum_v[i] << " ";
	cout << sum_v[n] << endl;
	return 0;
}

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

int n;
int tbl[11][11];

int main()
{
	while( std::cin >> n, n )
	{
		memset( tbl, 0, sizeof( tbl ) );

		for( int i = 0; i != n; ++i )
		{
			for( int j = 0; j != n; ++j )
			{
				std::cin >> tbl[i][j];
	
				tbl[i][n] += tbl[i][j];
				tbl[n][j] += tbl[i][j];
				tbl[n][n] += tbl[i][j];
			}
		}

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

	return 0;
}

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

int main(void){
	int n;
	while(cin>>n,n){
		int t[n+1][n+1];
		memset(t,0,sizeof(t));
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>t[i][j];
				t[n][j] += t[i][j];
				t[i][n] += t[i][j];
			}
		}

		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++){
				printf("%5d",t[i][j]);
				if(i < n && j == n) t[n][n] += t[i][j];
			}
			cout<<endl;
		}
	}

	return 0;
}

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

C++: #include<stdio.h>
#include<string.h>
#include<math.h>

int main(void){

    int n;
    int i,j;
    scanf("%d",&n);
    if(n==0)exit(0);
    int a[11][11]={{0}};
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            scanf("%d",&a[i][j]);
            }
        }
    for(i=0;i<n;i++){
        a[n][i]=a[0][i]+a[1][i]+a[2][i]+a[3][i]+a[4][i]+a[5][i]+a[6][i]+a[7][i]+a[8][i]+a[9][i];
    }
    for(j=0;j<n+1;j++){
        a[j][n]=a[j][0]+a[j][1]+a[j][2]+a[j][3]+a[j][4]+a[j][5]+a[j][6]+a[j][7]+a[j][8]+a[j][9];
    }
    for(i=0;i<=n;i++){
        for(j=0;j<=n;j++){
            printf("%5d",a[i][j]);
            }
            printf("\n");
        }

return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int n, tbl[15][15];
	
	while (cin >> n, n) {
		for_(i,0,n) for_(j,0,n) cin >> tbl[i][j];
		
		tbl[n][n] = 0;
		for_(i,0,n) {
			int sumi = 0, sumj = 0;
			
			for_(j,0,n) {
				sumi += tbl[i][j];
				sumj += tbl[j][i];
			}
			
			tbl[i][n] = sumi;
			tbl[n][i] = sumj;
			tbl[n][n] += sumi;
		}
		
		for_(i,0,n+1) {
			for_(j,0,n+1) printf("%5d", tbl[i][j]);
			cout << endl;
		}
	}
}

C++: #include <stdio.h>

int main(void)
{
	int a[11][11];
	int n, i, j;

	scanf("%d", &n);
	while (n != 0)
	{
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				scanf("%d", &a[i][j]);

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

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

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

	return 0;
}

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

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