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

int main()
{
	int n;

	while (scanf("%d", &n), n){
		int sum = 0, e_sum[10] = {0};
		for (int i = 0; i < n; i++){
			int num;
			int r_sum = 0;
			for (int j = 0; j < n; j++){
				scanf("%d", &num);
				r_sum += num;
				e_sum[j] += num;
				printf("%5d", num);
			}
			sum += r_sum;
			printf("%5d\n", r_sum);
		}

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

	return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;
int n;
void solve(){
  int table[200][200];

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

int main(){
  while (scanf("%d", &n), n)solve();
  return 0;
}

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

//0102
int main(){
	int n;
	while(cin >> n, n){
		int tbl[11][11]={0};

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

		for(int i=0; i<n+1; ++i){
			for(int j=0; j<n+1; ++j){
				cout.width(5);
				cout << tbl[i][j];
			}
			cout << endl;
		}
	}
	return 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) {
                if(j!=0) cout << " ";
                cout << G[i][j];
            }
            cout << setw(5) << endl;
        }
    }
    return 0;
}

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

int main(){

  int tab[11][11], n, low[11], colume[11], sum;

  while(cin >> n){
    if(n == 0) break;
    fill(low, low+11, 0);
    fill(colume, colume+11, 0);
    
    for(int i=0; i<=n; i++){
      sum = 0;
      if(i != n){
        for(int j=0; j<n; j++){
          cin >> tab[i][j];
          sum += tab[i][j];
          low[j] += tab[i][j];
        }
      }
      else{
        for(int j=0; j<n; j++){
          tab[i][j] = low[j];
          sum += low[j];
        }
      }

      tab[i][n] = sum;

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

  return 0;

}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    vector<vector<int>> vec(n + 1, vector<int>(n + 1, 0));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> vec[i][j];
        vec[i][n] += vec[i][j];
        vec[n][j] += vec[i][j];
      }
    }
    vec[n][n] = accumulate(vec[n].begin(), vec[n].end(), 0);

    for (auto &seq : vec) {
      for (auto &v : seq)
        cout << setw(5) << v;
      cout << endl;
    }
  }
}

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

int main(){
	int n;

	while(cin >> n, n){
		vector<int> vsum(n);
		int hsum = 0;
		int k;
		for(int i = 0; i < n; i++){
			int sum = 0;
			for(int j = 0; j < n; j++){
				cin >> k;
				printf("%5d", k);
				sum+=k;
				vsum[j]+=k;
			}
			printf("%5d\n", sum);
			hsum += sum;
		}
		vsum.push_back(hsum);

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

	return 0;
}

C++: #include<stdio.h>
int d[10][10];
int t[10][10];
int n;
int i,j;
int res;

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

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

using namespace std;

int main() {
	int num;
	while(cin>>num, !cin.eof()) {
		if(num==0) break;
		int table[num][num];
		int col_num[num];

		for(int i=0; i<num; i++){
			for(int j=0; j<num; j++){
				cin>>table[i][j];
			}
		}
		int all_sum = 0;
		for(int i=0; i<num; i++){
			int row_sum = 0;
			for(int j=0; j<num; j++){
				cout<< setw(5)<<right <<table[i][j];
				row_sum +=table[i][j];
				col_num[j] += table[i][j];
			}
			cout<< setw(5)<<right<< row_sum<<endl;
			all_sum += row_sum;
		}

		for(int i=0; i<num; i++){
			cout<< setw(5)<<right<< col_num[i];
		}
		cout<< setw(5)<<right <<all_sum<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<vector<int> > num(n+1, vector<int>(n+1, 0));
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                cin >> num[i][j];
                num[i][n] += num[i][j];
                num[n][j] += num[i][j];
                num[n][n] += num[i][j];
            }
        }

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

C++: #include<iostream>
using namespace std;
int main()
{
	int n,sum=0,sumy=0;
	while (1){
		sum = 0;
		sumy = 0;
		cin >> n;
		if (n == 0)break;
		int ma[101][101] = { 0 };
		for (int i = 0; i < n; i++){
			sum = 0;
			for (int i2 = 0; i2 < n; i2++){
				cin >> ma[i][i2];
				sum += ma[i][i2];

			}
			sumy += sum;
			ma[i][n] += sum;
		}
		ma[n][n] += sumy;
		for (int i = 0; i < n; i++){
			sum = 0;
			for (int i2 = 0; i2 < n; i2++){
				sum += ma[i2][i];
				sumy += sum;
			}
			ma[n][i] += sum;
		}
		n++;
		for (int i = 0; i < n; i++){
			for (int i2 = 0; i2 < n; i2++){
				printf("%5d", ma[i][i2]);
			}
			cout << endl;
		}
	}
}

C++: //#define scanf_s scanf
//#define sscanf_s sscanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 11
#define HO 6
int main(void)
{
	int n;
	while (1) {
		scanf_s("%d", &n);
		if (n == 0) break;
		int date[MAX][MAX] = { 0 };
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				scanf_s("%d", &date[i][j]);
				date[i][n] += date[i][j];
				date[n][j] += date[i][j];
				date[n][n] += date[i][j];
			}
		}
		for (int i = 0; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				printf("%5d", date[i][j]);
			}
			printf("\n");
		}
		
	}
}