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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

int n;


int main(){
    while(cin>>n){
        if(n==0)break;
        int box[11][11]={0};
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                cin>>box[i][j];
            }
        }
        
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                box[i][n]+=box[i][j];
            }
        }
        
        for(int i=0; i<n; i++){
            for(int j=0; j<=n; j++){
                box[n][j]+=box[i][j];
            }
        }
        
        for(int i=0; i<=n; i++){
            for(int j=0; j<=n; j++){
                cout.width(5);
                cout<<box[i][j];
            }
            cout<<endl;
        }
        
    }
}

C++: #include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
int in[11][11]={0};
int main(){
int n;
while(cin>>n,n){
rep(i,n){
int sum=0,j;
for(j=0;j<n;j++){
int tmp;
cin>>tmp;
sum+=tmp;
in[i][j]=tmp;
printf("%5d ",tmp);
}
in[i][j]=sum;
printf("%5d\n",sum);
}

rep(i,n+1){
int sum=0;
rep(j,n){
sum+=in[j][i];
}
if(i!=n)printf("%5d ",sum);
else printf("%5d\n",sum);
}
}
}

C++: #include<iostream>
#include<iomanip>
using namespace std;
int main(void)
{
    int n,A=0,ober[10][10],side[10],lon=0;
    while(1){
        for(int i=0;i<12;i++)side[i]=0;
        cin>>n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cin>>ober[i][j];
                side[j]+=ober[i][j];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                cout<<setw(4)<<ober[i][j]<<" ";
                A+=ober[i][j];
            }
            cout<<setw(4)<<A<<"\n";
            lon+=A;
            A=0;
        }
        for(int i=0;i<n;i++)cout<<setw(4)<<side[i]<<" ";
        cout<<setw(4)<<lon<<"\n";
        lon=0;
    }
}

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

#define int long long

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

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

int main(){
	int n;
	while(std::cin>>n,n){
		int data[10][10];
		memset(data,0,sizeof(data));
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				std::cin>>data[i][j];
				data[i][n]+=data[i][j];
				data[n][j]+=data[i][j];
				data[n][n]+=data[i][j];
			}
		}
		for(int i=0;i<n+1;i++){
			for(int j=0;j<n+1;j++){
				std::cout<<std::setw(5)<<std::right<<data[i][j];
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

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

int main(){
	int n;
	while(cin >> n,n){
		int data[10+1][10+1];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}

		int all_sum = 0;

		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = 0; j < n; j++){
				sum += data[i][j];
			}
			data[i][n] = sum;
			all_sum += sum;
		}




		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = 0; j < n; j++){
				sum += data[j][i];
			}
			data[n][i] = sum;
		}
			data[n][n] = all_sum;


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

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

using namespace std;

int main()
{
	int n, num[11][11];
	while (1) {
		if (cin >> n, !n) break;
		
		for (int i=0; i<11; i++) for (int j=0; j<11; j++) num[i][j] = 0;
		
		for (int i=0; i<n; i++) for (int j=0; j<n; j++) cin >> num[i][j];
		
		for (int i=0; i<10; i++)
			for (int j=0; j<10; j++) num[10][i] += num[j][i];
		
		for (int i=0; i<11; i++)
			for (int j=0; j<10; j++) num[i][10] += num[i][j];
		
		for (int i=0; i<11; i++) {
			for (int j=0; j<11; j++) {if ((i<n && j<n) || (i==10 && j<n) || (j==10 && i<n) || (j==10 && i==10)) {cout.width(5); cout << num[i][j];}}
			if ((i < n) || (i == 10))  cout << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main(){
	int n[127], tn=0,ni=0,all = 0, i = 0;
	int data[1024][10];
	int tdata[10] = { 0 };
	
		//input
	while (1){
		cin >> n[ni];
		if (n[ni] == 0)break;
		tn += n[ni];
		ni++;

		for (; i < tn; i++){
			for (int j = 0; j < n[ni]; j++){
				cin >> data[i][j];
			}
		}
	}
	

	//output
	for (int k = 0; k < ni; k++){
		for (int i = 0; i < tn; i++, all = 0){
			for (int j = 0; j < n[k]; j++){
				printf(" %5d", data[i][j]);
				all += data[i][j];
				tdata[j] += data[i][j];
			}
			printf(" %5d\n", all);
		}

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

		for (int i = 0; i < n[k]; i++){
			tdata[i] = 0;
		}
		all = 0;
	}
	return 0;
}

C++: #include <cstdio>

int main(){
  int n;
  
  while(1){
    scanf("%d", &n);
    if(!n) break;
    
    int table[11][11] = {0};
    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][i] += table[j][i];
      }
    }
    
    for(int i=0; i<n; i++)
      table[n][n] += table[n][i];
    
    for(int i=0; i<=n; i++){
      for(int j=0; j<n; j++)
	printf("%5d", table[i][j]);
      putchar('\n');
    }
  }
    
  return 0;
}

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

using namespace std;

string disp(int a){
	string ans = "     ";
	if(a == 0){
		ans = "    0";
		return ans;
	}
	ans[0] = (a / 10000) + '0';
	ans[1] = (a / 1000) % 10 + '0';
	ans[2] = (a / 100) % 10 + '0';
	ans[3] = (a / 10) % 10 + '0';
	ans[4] = a % 10 + '0';
	
	for(int i = 0; i <= 4; i++){
		if(ans[i] == '0'){
			ans[i] = ' ';
		}else{
			break;
		}
	}
	
	return ans;
}

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