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()
{
  while (true)
  {
    int n;
    cin >> n;
    if ( n == 0 ) break;
    int **array = new int*[n+1];
    for (int i=0; i<n+1; i++)
    {
      array[i] = new int[n+1];
    }

    for (int i=0; i<n+1; i++)
    {
      for (int j=0; j<n+1; j++)
      {
        array[i][j] = 0;
      }
    }

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

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

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

    for (int i=0; i<n+1; i++)
    {
      delete[] array[i];
    }
    delete[] array;
  }
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,glap[12][12]={0},all;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>glap[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            glap[i][n]+=glap[i][j];
            glap[n][i]+=glap[j][i];
        }
    }
    for(int i=0;i<n;i++){
        glap[n][n]+=glap[n][i];
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            printf("%5d",glap[i][j]);
        }
        cout<<endl;
    }
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <climits>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    while (cin >> n && n) {
        vector<vector<int>> mat(n+1, vector<int>(n+1, 0));
        for (int i=0; i<n; ++i) {
            for (int j=0; j<n; ++j) {
                cin >> mat[i][j];
                mat[n][j] += mat[i][j];
                mat[i][n] += mat[i][j];
                mat[n][n] += mat[i][j];
            }
        }
        for (int i=0; i<n+1; ++i) {
            for (int j=0; j<n+1; ++j) {
                cout << setw(5) << mat[i][j];
            }
            cout << endl;
        }
    }

    return 0;
}

C++: #include <stdio.h>

int main(void){
	int matrix[11][11],i,j,dataset;
	while(scanf("%d",&dataset)){

		if(dataset==0)break;

		//init add total norm
		for(i=0;i<dataset+1;i++){
			matrix[dataset][i]=0;
			matrix[i][dataset]=0;
		}

		//input and calc
		for(i=0;i<dataset;i++){
			for(j=0;j<dataset;j++){
				scanf("%d",&matrix[i][j]);
				matrix[i][dataset]+=matrix[i][j];
			}
		}

		//calc
		for(j=0;j<dataset+1;j++){
			for(i=0;i<dataset;i++){
				matrix[dataset][j]+=matrix[i][j];
			}
		}

		//output
                for(i=0;i<dataset+1;i++){
                        for(j=0;j<dataset+1;j++){
                                printf("%5d",matrix[i][j]);
                        }
			printf("\n");
                }
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main() {
    int n;
    while(1){
        cin>>n;
        if(n==0)return 0;
        vector<vector<int>> v(n+1,vector<int>(n+1,0));
        
        rep(i,0,n){
            int sum=0;
            rep(j,0,n){
                cin>>v[i][j];
                sum+=v[i][j];
            }
            v[i][n]=sum;
        }
        
        rep(j,0,n+1){
            int sum=0;
            rep(i,0,n){
                sum+=v[i][j];
            }
            v[n][j]=sum;
        }
        
        rep(i,0,n+1){
            rep(j,0,n+1){
                if(j==0)printf("%5d",v[i][j]);
                else printf("%5d",v[i][j]);
            }
            cout<<endl;
        }
        
        
    }
    return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<set>
#include<iomanip>
int elem[11][11];
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 << setw(5) << elem[i][j];
			}cout << endl;
		}
	}
	return 0;
}

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

int main(){
    int n;

    while(cin >> n, n != 0){
        int matrix[n+1][n+1];
        int rowsum, colsum;
        int allsum = 0;

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

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

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

    return 0;
}

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

using namespace std;

int main(){
	int n,all=0;
	int data[256][256];
	int tdata[256] = { 0 };
	
	while (1){
		//input
		cin >> n;
		if (n == 0)break;

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

		//output

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

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