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

int main(){
	int n;
	int matrix[100][100];
	while(cin >> n){
		if(n==0) return 0;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				cin >> matrix[i][j];
			}
		}
		int sumX[100],sumY[100],sum=0;		
		for(int i=0; i<n; i++){
			sumX[i]=0; sumY[i]=0;
			for(int j=0; j<n; j++){
				sumX[i] += matrix[j][i];
				sumY[i] += matrix[i][j];
			}
			sum+=sumX[i];
		}
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				printf("%5d",matrix[i][j]);
			}
			printf("%5d\n",sumY[i]);
		}
		for(int i=0; i<n; i++) printf("%5d",sumX[i]);
		printf("%5d\n",sum);
		
	}
}

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

using namespace std;

int main() {
    
    int n;
    cin >> n;
    
    int A[51][51] = {};
    
    for(int i=0;i<n;i++) { 
    for(int j=0;j<n;j++) {
    	
    	cin >> A[i][j];
    	
    	A[i][n] += A[i][j];
    	A[n][j] += A[i][j];
	}
	A[n][n] += A[i][n];
}

	for(int i=0;i<=n;i++) { 
    for(int j=0;j<=n;j++) {
    	
    	cout << setw(4)<< A[i][j] << " ";
    
	}
	cout << "\n";
}
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#define MAX_N 15
using namespace std;
int main(){
	int n,i,j;
	while(1){
		cin >> n;
		if(n==0)break;
		int a[MAX_N][MAX_N];
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				a[i][j]=0;
			}
		}


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

		int sum1=0,sum[MAX_N];
		for(i=0;i<n;i++){
			for(j=0;j<=n;j++){
				sum1+=a[i][j];
				if(j==n){
					a[i][j]=sum1;
					sum1=0;
				}
			}
		}

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


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

	}
	return 0;
}

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

int main(){
	int data_size;
	cin >> data_size;
	while (data_size){
		vector<vector<int>> data;
		vector<vector<int>> data_digit;
		data.resize((data_size + 1)*(data_size + 1));
		data_digit.resize((data_size + 1) * (data_size + 1));
		for (int i = 0; i < data_size; i++){
			data[i].resize(data_size + 1);
			data_digit[i].resize(data_size + 1);
			for (int j = 0; j < data_size; j++){
				cin >> data[i][j];
				int tmp = data[i][j];
				data_digit[i][j] = 0;
				while (tmp){
					tmp /= 10;
					data_digit[i][j]++;
				}
			}
		}
		data[data_size].resize(data_size + 1);
		data_digit[data_size].resize(data_size + 1);
		for (int i = 0; i < data_size; i++){
			int sum = 0;
			for (int j = 0; j < data_size; j++){
				sum += data[i][j];
			}
			data[i][data_size] = sum;
			int tmp = sum;
			data_digit[i][data_size] = 0;
			while (tmp){
				tmp /= 10;
				data_digit[i][data_size]++;
			}

		}
		for (int i = 0; i < data_size + 1; i++){
			int sum = 0;
			for (int j = 0; j < data_size; j++){
				sum += data[j][i];
			}
			data[data_size][i] = sum;
			int tmp = sum;
			data_digit[data_size][i] = 0;
			while (tmp){
				tmp /= 10;
				data_digit[data_size][i]++;
			}
		}

		for (int i = 0; i < data_size + 1; i++){
			for (int j = 0; j < data_size + 1; j++){
				for (int k = data_digit[i][j]; k < 5; k++){
					cout << " ";
				}
				cout << data[i][j];
			}
			cout << "\n";
		}
		cin >> data_size;
	}
	return 0;
}

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

vector<vector<int> > data;

void init(){
  data.clear();
}

bool input(){
  int n;
  cin>>n;
  if(n==0)return false;

  for(int i=0;i<n;i++){
    vector<int> vtmp;
    for(int j=0;j<n;j++){
      int tmp;
      cin>>tmp;
      vtmp.push_back(tmp);
    }
    data.push_back(vtmp);
  }
  return true;
}

void solve(){
  vector<int> last;
  last.resize(data[0].size()+1);
  for(int i=0;i<data.size();i++){
    int tmp=0;
    for(int j=0;j<data[i].size();j++){
      tmp+=data[i][j];
      last[j]+=data[i][j];
      last[last.size()-1]+=data[i][j];
    }
    data[i].push_back(tmp);
  }
  data.push_back(last);
}


int main(){
  while(init(),input()){
    solve();
    for(int i=0;i<data.size();i++){
      for(int j=0;j<data[i].size();j++){
        cout<<setw(5)<<data[i][j];
      }cout<<endl;
    }
  }
}

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(5)<<ober[i][j]<<" ";
                A+=ober[i][j];
            }
            cout<<setw(5)<<A<<"\n";
            lon+=A;
            A=0;
        }
        for(int i=0;i<n;i++)cout<<setw(5)<<side[i]<<" ";
        cout<<setw(5)<<lon<<"\n";
        lon=0;
    }
}

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

int main(){
    int number;
    int sum = 0;
    
    while(1){
        cin >> number;
        if (number == 0){
            break;
        }
        
       
        int array[number][number];
        int lastColumn[number];
        int lastRow[number];
        int total=0;
        
        for(int i=0; i<number; i++){
            sum = 0;
            for(int j=0; j<number; j++){
                cin >> array[i][j];
                sum += array[i][j];
            }
            lastColumn[i] = sum;
        }
        
        for(int j=0; j<number; j++){
            sum = 0;
            for(int i=0; i<number; i++){
                sum += array[i][j];
            }
            lastRow[j] = sum;
            total +=sum;
        }
        
        for(int i=0; i<number; i++){
            for(int j=0; j<number; j++){
                printf("%5d ", array[i][j]);
            }
            cout << lastColumn[i] <<"\n";
        }
        
        for(int i=0; i<number; i++){
            printf("%5d ", lastRow[i]);
         }
        printf("%5d\n", total);

    }
    
    return 0;
}

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

int main(void){
	int n,tmp;
	while ( cin >> n ,n){
		int list[11][11]={0};
		for(int j=0;j<n;j++)
			for(int i=0;i<n;i++)
				cin >> list[i][j];
		for(int j=0;j<n;j++)
			for(int i=0;i<n;i++)
				list[n][j]+=list[i][j];
		for(int i=0;i<=n;i++)
			for(int j=0;j<n;j++)
				list[i][n]+=list[i][j];
		for(int j=0;j<=n;j++){
			for(int i=0;i<=n;i++){
				printf("%5d",list[i][j]);
				//printf(i?" ":"");
			}
			printf("\n");
		}
	}
	return 0;
}

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

int main()
{
	int n,sum,i,sumsum=0;
	int array[11]={0};
	while(1){
		for(i=0;i<11;i++) array[i]=0;
		cin >> n;
		int loop = n;
		if(!n)break;
		while(loop--){
			sum = 0;
			for(i=0;i<n;i++){
				int x;
				cin >> x;
				cout << x << "\t";
				sum += x;
				array[i] += x;
			}
			cout << sum << "\n";
		}
		for(i=0;i<n;i++){
			cout << array[i] << "\t";
			sumsum += array[i];
		}
	cout << sumsum << "\n";
	sumsum=0;
	}
	return 0;
}