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

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int dt[n+1][n+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>dt[i][j];
			}
		}
		for(int x=0;x<n+1;x++){
			dt[x][n]=0;
		}
		for(int y=0;y<n;y++){
			dt[n][y]=0;
		}
		for(int k=0;k<n;k++){
			for(int l=0;l<n;l++){
				dt[k][n]+=dt[k][l];
			}
		}
		for(int x=0;x<=n;x++){
			for(int y=0;y<n;y++){
				dt[n][x]+=dt[y][x];
			}
		}
		for(int a=0;a<=n;a++){
			for(int b=0;b<=n;b++){
				if(dt[a][b]/10==0)cout<<"    "<<dt[a][b];
				else if(dt[a][b]/100==0)cout<<"   "<<dt[a][b];
				else if(dt[a][b]/1000==0)cout<<"  "<<dt[a][b];
				else if(dt[a][b]/10000==0)cout<<" "<<dt[a][b];
			}
			cout<<endl;
		}
	}
	return 0;
}

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

int main(){
  int n;
  while(std::cin>>n){
    if(!n)return 0;
    int v[11][11] = {0};
    for(int i=0;i<n;i++){
      std::string s;
      std::cin.get();
      getline(std::cin,s);
      std::stringstream ss(s);
      int num;
      for(int j=0;j<n;j++){
      ss>>num;
      v[j][i]=num;
      v[n][i]+=num;
      v[j][n]+=num;
      v[n][n]+=num;
      }
    }

    for(int y=0;y<=n;y++){
      for(int x=0;x<=n;x++){
        std::cout<<std::right<<std::setw(5)<<v[x][y];
      }
      std::cout<<std::endl;
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n,s[11];
	while(cin>>n,n){
		fill(s,s+10,0);
		for(int i=0;i<n;i++){
			int y=0,t;
			for(int j=0;j<n;j++){
				cin>>t;
				y+=t;
				s[j]+=t;
				cout<<t<<" ";
			}
			cout<<y<<endl;
		}
		int l=0;
		for(int i=0;i<n;i++){ cout<<s[i]<<" "; l+=s[i]; }
		cout<<l<<endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/2)
#define PI (2*acos(0.0))
#define EPS (1e-8)

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(void){
  ios_base::sync_with_stdio(0);
  int n;
  while(cin >> n, n){
    vector< vector<int> > vec(n + 1, vector<int>(n + 1, 0));
    for(int i = 0; i < n; i++){
      int sum = 0;
      for(int j = 0; j < n; j++){
        cin >> vec[i][j];
        sum += vec[i][j];
      }
      vec[i][n] = sum;
    }

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

C++: #include<stdio.h>
int main(void)
{
	int n,x[101][101],i,j,sum,y;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++) scanf("%d",&x[i][j]);
		}
		for(i=0;i<n;i++){
			sum=0;
			for(j=0;j<n;j++) sum+=x[j][i];
			x[n][i]=0;
			x[n][i]=sum;
		}
		for(i=0;i<=n;i++){
			sum=0;
			for(j=0;j<n;j++) sum+=x[i][j];
			x[i][n]=0;
			x[i][n]=sum;
		}
		y=0;
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				y=x[i][j];
				if(y==0) y=1;
				while(y<1000){
					printf(" ");
					y*=10;
				}
				if(j!=n) printf("%d ",x[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
#include <algorithm>

#define int64 long long int
using namespace std;

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

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;



int main(){

	int n,tmp,row_sum,col_sum[11];

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i=0; i < 11; i++)col_sum[i] = 0;

		for(int i=0; i < n; i++){
			row_sum = 0;
			for(int k=0; k < n; k++){
				scanf("%d",&tmp);
				printf("%5d",tmp);
				row_sum += tmp;
				col_sum[k] += tmp;
			}
			printf("%5d\n",row_sum);
			col_sum[n] += row_sum;
		}
		for(int i=0; i <= n; i++)printf("%5d",col_sum[i]);
		printf("\n");
	}

    return 0;
}

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

using namespace std;

int main()
{
    int n;
    
    while (true) {
        cin >> n;
        if (!n) {
            break;
        }
        vector<vector<int> > v(n + 1, vector<int>(n + 1, 0));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> v[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[i][n] += v[i][j];
            }
            v[n][n] += v[i][n];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v[n][i] += v[j][i];
            }
            v[n][n] += v[n][i];
        }
        for (int i = 0; i < n + 1; i++) {
            for (int j = 0; j < n + 1; j++) {
                if (j > 0) {
                    cout << ' ';
                }
                cout << setw(5) << v[i][j];
            }
            cout << '\n';
        }
    }
}

C++: 
#include <iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(){
    int a[10][10],n,i,j,tate[10]={0},yoko[10]={0},sum=0;
    while(cin>>n){
        if(n==0)break;
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                cin>>a[i][j];
                sum+=a[i][j];
                yoko[i]+=a[i][j];
                tate[j]+=a[i][j];
            }
        }
        for(i=0;i<n;i++){
            for(j=0;j<=n;j++){
                if(j==n)printf("%5d\n",yoko[i]);
                else printf("%5d",a[i][j]);
            }
        }
        for(j=0;j<=n;j++){
            if(j!=n)printf("%5d",tate[j]);
            else if(j==n)printf("%5d\n",sum);
        }
    }
     return 0;
}