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>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,hyo[11][11],n,wa[4],wa2[4],sum;
	while(1) {
		scanf("%d",&n);
		if(n==0)  break;
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) scanf("%d",&hyo[i][j]);
		}
		for(i=0;i<n;i++) {
			sum=0;
			for(j=0;j<n;j++) sum+=hyo[i][j];
			wa[i]=sum;
		}
		for(i=0;i<n;i++) {
			sum=0;
			for(j=0;j<n;j++) sum+=hyo[j][i];
			wa2[i]=sum;
		}
		for(i=0;i<n;i++) {
			for(j=0;j<n;j++) {
				if(hyo[i][j]==100) printf(" %d ",hyo[i][j]);
				if(hyo[i][j]<100 && hyo[i][j]>=10) printf("  %d ",hyo[i][j]);
			}
			printf("%d\n",wa[i]);
		}
		for(i=0;i<4;i++) {
			if(wa2[i]>=1000) printf("%d ",wa2[i]);
			if(wa2[i]>=100 && wa2[i]<1000) printf(" %d ",wa2[i]);
			else printf("   %d ",wa2[i]);
		}
		sum=0;
		for(i=0;i<4;i++) {
			sum+=wa[i];
		}
		if(sum==1000) printf("%d\n",sum);
		if(sum<1000 && sum>=10) printf("%d\n",sum);
	}
	return 0;
}

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

int main(){
	double num[12][12]={};
	int N ;
int a=0;
while(1)
{cin>>N;
if(N==0)break;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++)
{cin>>num[i][j];num[i][N]+=num[i][j];}
}
for(int i=0;i<N;i++)
num[N][N]+=num[i][N];
for(int i=0;i<N;i++)
	for(int j=0;j<N;j++)
num[N][i]+=num[j][i];

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++)
{
printf("5%lf",num[i][;}
cout<<endl;


}

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){
num[i][j]=0;
}
}


}

return 0;
}

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

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

C++: #include<stdio.h>

int a[1000][1000],i,j,n;

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

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

int main() {
  int n = 0, tmp0 = 0, tmp1 = 0;
  int tmp2 = 0, tmp3, out1 = 0, out2 = 0;
  int a[100];
  scanf("%d", &n);
  while (n) {
    for (tmp3=0;tmp3<100;tmp3++) a[tmp3] = 0;
    tmp0 = 0, out2 = 0;
    while (tmp0 < n) {
      tmp1 = 0, out1 = 0;
      while (tmp1 < n) {
        scanf("%d", &tmp2);
        a[tmp1] += tmp2;
        printf("%5d", tmp2);
        out1 += tmp2;
        tmp1++;
      }
      printf("%5d\n", out1);
      a[tmp1] += out1;
      tmp0++;
    }
    tmp0 = 0;
    while (tmp0 < n) {
      printf("%5d", a[tmp0]);
      tmp0++;
    }
    printf("%5d\n", a[tmp0]);
    scanf("%d", &n);
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  while(cin>>n,n) {
    int a[n+1][n+1];
    REP(y,n) {
      int sum=0;
      REP(x,n) {
        cin >> a[x][y];
        sum += a[x][y];
      }
      a[n][y] = sum;
    }
    int sum2 = 0;
    REP(x,n) {
      int sum =0;
      REP(y,n) {
        sum+=a[x][y];
      }
      a[x][n] = sum;
      sum2+=sum;
    }
    a[n][n] = sum2;
    REP(y,n+1) {
      REP(x,n+1) {
        printf("%5d",a[x][y]);
      }
      cout << endl;
    }
  }
}

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

int main(){
	
	int n ;
	while( cin >> n , n ){
		
		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++ ){
			for( int j=0 ; j<=n ; j++ ){
				if( m[i][j] < 10 ) cout << ' ' ;
				if( m[i][j] < 100 ) cout << ' ' ;
				if( m[i][j] < 1000 ) cout << ' ' ;
				if( m[i][j] < 10000 ) cout << ' ' ;
				cout << m[i][j] ;
			}
			cout << endl ;
		}
	}
	
return 0 ;
}

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

int n;

int solve(int n){
        int format=0,table[1000][1000]={};
        for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                        cin >> table[i][j];
                }
        }
        for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                        table[n][j] += table[i][j];
                        table[i][n] += table[i][j];
                }
        }
        for(int i=0;i<n;i++){
                table[n][n] += table[i][n];
                table[n][n] += table[n][i];
        }
        table[n][n] /= 2;
        if(table[n][n] < 10){
                format=1;
        }else if(table[n][n] < 100){
                format=2;
        }else if(table[n][n] < 1000){
                format=3;
        }else if(table[n][n] < 10000){
                format=4;
        }
        for(int i=0;i<n+1;i++){
                for(int j=0;j<n+1;j++){
                        cout << setw(format) << table[i][j];
                        cout << " ";
                }
                cout << "" << endl;
        }
}

int main(){
        while(1){
                cin >> n;
                if(n == 0){
                        break;
                }
                solve(n);
        }
}

C++: #include <iostream>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main()
{
	int a[101][101];
	int n;
	while(cin >> n && n)
	{
		memset(a,0,sizeof(a));
		rep(i,n)
		{
			rep(j,n)
			{
				cin >> a[i][j];
			}
		}

		int sum_n = 0;
		rep(i,n)
		{
			int sum = 0;
			int sum_2 = 0;
			rep(j,n)
			{
				sum += a[i][j]; 
				sum_2 += a[j][i];
			}
			a[i][n] = sum;
			a[n][i] = sum_2;

			sum_n += a[i][n];
		}

		a[n][n] = sum_n;

		rep(i,n+1)
		{
			rep(j,n+1)
			{
				cout.width(5);
				cout << a[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}