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 <bits/stdc++.h>

using namespace std;

int n;
int tb[11][11];

int main() {
	while (1) {
		cin >> n; if (n == 0) break;
		memset(tb, 0, sizeof(tb));
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> tb[i][j];
			}
		}
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				tb[i][n] += tb[i][j];
				tb[n][j] += tb[i][j];
				tb[n][n] += tb[i][j];
			}
		}
		
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				cout << setw(5) << tb[i][j];
			}
			cout << endl;
		}
	}	
	
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(void) {
	int n, tmp, sum, suml[10];
	int i, j;

	while(true) {
		cin >> n;
		if(n == 0) { break; }
		for(i = 0; i < 10; i++) {
			suml[i] = 0;
		}
		for(i = 0; i < n; i++) {
			sum = 0;
			for(j = 0; j < n; j++) {
				cin >> tmp;
				cout.width(5);
				cout << tmp;
				suml[j] += tmp;
				sum += tmp;
			}
			cout.width(5);
			cout << sum << endl;
		}
		sum = 0;
		for(i = 0; i < n; i++) {
			cout.width(5);
			cout << suml[i];
			sum += suml[i];
		}
		cout.width(5);
		cout << sum << endl;
	}

	return 0;
}

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

int main(){
  int n,sumw,sumh;
  while(1){
    cin>>n;
    if(n==0)break;
    int array[n+1][n+1];
    for(int i=0;i<n;i++){
      sumw=0;
      for(int j=0;j<n;j++){
	cin>>array[i][j];
	sumw+=array[i][j];
      }
      array[i][n]=sumw;
    }
    for(int i=0;i<n+1;i++){
      sumh=0;
      for(int j=0;j<n;j++){
	sumh+=array[j][i];
      }
      array[n][i]=sumh;
    }
    for(int i=0;i<n+1;i++){
      cout<<" ";
      for(int j=0;j<n+1;j++){
	printf("%5d",array[i][j]);
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  while(true){
  cin>>n;
  if(!n)break;
  int table[n+1][n+1];
  for(int y=0;y<n;y++){
    int s = 0;
    for(int x=0;x<n;x++){
      cin>>table[x][y];
      s+=table[x][y];
    }
    table[n][y] = s;
  }
  for(int x=0;x<n+1;x++){
    int s = 0;
    for(int y=0;y<n;y++){
      s+=table[x][y];
    }
    table[x][n] = s;
  }
  for(int y=0;y<n+1;y++){
    for(int x=0;x<n+1;x++){
      printf("%5d",table[x][y]);
    }
    printf("\n");
  }
  }
  return 0;
}

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

using namespace std;

int main(){
  int mat[11][11];
  for(int n;cin>>n,n;){
    for(int y=0;y<n;y++){
      int s=0;
      for(int x=0;x<n;x++){
	cin>>mat[y][x];
	s+=mat[y][x];
      }
      mat[y][n]=s;
    }
    for(int x=0;x<=n;x++){
      int s=0;
      for(int y=0;y<n;y++){
	s+=mat[y][x];
      }
      mat[n][x]=s;
    }
    for(int y=0;y<=n;y++){
      for(int x=0;x<=n;x++){
	cout<<setw(5)<<right<<mat[y][x];
      }
      cout<<endl;
    }
  }
  return 0;
}

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

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		vector< vector<int> > Vec(N + 1, vector<int>(N + 1));
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				cin >> Vec[i][j];
			}
		}
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				Vec[i][N] += Vec[i][j];
				Vec[N][i] += Vec[j][i];
			}
		}
		for(int i = 0; i < N; ++i)
		{
			Vec[N][N] += Vec[i][N];
		}
		for(int i = 0; i < N + 1; ++i)
		{
			for(int j = 0; j < N; ++j)
			{
				printf("%5d", Vec[i][j]);
			}
			printf("%5d\n", Vec[i][N]);
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	
	while(cin >> n && n)
	{
		vector<vint> v(n + 1, vint(n + 1));

		rep(i, n) rep(j, n)
			cin >> v[i][j];

		rep(i, n) 
		{
			rep(j, n)
			{
				v[i][n] += v[i][j];
				v[n][i] += v[j][i];
			}
		}

		rep(i, n+1) 
		{
			rep(j, n+1)
			{
				cout << v[i][j];
				if(j < n) cout << " ";
			}
			cout << endl;
		}
	}
}

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

int main() {
	int N;

	while (cin >> N && N != 0) {
		int dataset[N+1][N+1];
        for (int i = 0; i != N; ++i) {
            for (int j = 0; j != N; ++j) {
                cin >> dataset[i][j];
            }
        }

        for (int i = 0; i != N; ++i) {
            int total = 0;
            for (int j = 0; j != N; ++j) {
                total += dataset[i][j];
            }
            dataset[i][4] = total;
        }

        for (int i = 0; i != N; ++i) {
            int total = 0;
            for (int j = 0; j != N; ++j) {
                total += dataset[j][i];
            }
            dataset[4][i] = total;
        }

        int ans = 0;
        for (int i = 0; i != N; ++i) {
            ans += dataset[4][i] + dataset[i][4];      
        }
        dataset[4][4] = ans;

        for (int i = 0; i != N+1; ++i) {
            for (int j = 0; j != N+1; ++j) {
                cout << setw(5) << dataset[i][j];
            } 
            cout << endl;
        }
	}
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define ub upper_bound
#define lb lower_bound
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  int M[12][12];
  while(cin>>n,n){
    rep(i,n)rep(j,n)cin>>M[i][j];
    rep(i,n){
      int tmp=0;
      rep(j,n)tmp+=M[i][j];
      M[i][n]=tmp;
    }
    rep(i,n){
      int tmp=0;
      rep(j,n)tmp+=M[j][i];
      M[n][i]=tmp;
    }
    int tmp=0;
    rep(i,n)tmp+=M[n][i];
    M[n][n]=tmp;
    rep(i,n+1){
      rep(j,n+1){
        cout<<M[i][j];
        if(j<n+1)cout<<' ';
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	while (n != 0) {
		int a[10][10] = {}, sum_h[11] = {}, sum_v[11] = {};
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> a[i][j];
				printf("%5d",a[i][j]);
				sum_h[i] += a[i][j];
				sum_v[j] += a[i][j];
			}
			sum_v[n] += sum_h[i];
			printf("%5d\n", sum_h[i]);
		}
		for (int i = 0; i < n; i++)
			printf("%5d", sum_v[i]);
		printf("%5d\n", sum_v[n]);
		cin >> n;
	}
	return 0;
}