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 <stdio.h>
 
int main(void)
{
    int a[11][11];
    int n, i, j;
 
    scanf("%d", &n);
    while (n != 0)
    {
        for (i = 0; i < n; i++)
            for (j = 0; j < n; j++)
                scanf("%d", &a[i][j]);
 
        a[n][n] = 0;
        for (i = 0; i < n; i++)
        {
            a[i][n] = 0;
            for (j = 0; j < n; j++)
                a[i][n] += a[i][j];
            a[n][n] += a[i][n];
        }
 
        for (j = 0; j < n; j++)
        {
            a[n][j] = 0;
            for (i = 0; i < n; i++)
                a[n][j] += a[i][j];
        }
 
        for (i = 0; i <= n; i++)
        {
            for (j = 0; j <= n; j++)
                printf("%5d", a[i][j]);
            printf("\n");
        }
         
        scanf("%d", &n);
    }
 
    return 0;
}

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

int main() {
  int n, sum, a;
  vector<int> v;

  while (cin >> n && n) {
    v.resize(n);
    for (int i=0; i<n; i++) v[i] = 0;
    for (int i=0; i<n; i++) {
      sum = 0;
      for (int j=0; j<n; j++) {
        cin >> a;
        cout << setw(5) << a;
        v[j] += a;
        sum += a;
      }
      cout << setw(5) << sum << endl;
    }
    sum = 0;
    for (int i=0; i<n; i++) {
      sum += v[i];
      cout << setw(5) << v[i];
    }
    cout << setw(5) << sum << endl;
  }

  return 0;
}

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

int main(){
	int n;
	int area[11][11];
	while(cin >> n){
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> area[i][j];
			}
		}
		for(int i = 0; i < n; i++){
			int count = 0;
			for(int j = 0; j < n; j++){
				count += area[i][j];
			}
			area[i][n] = count;
		}
		for(int j = 0; j <= n; j++){
			int count = 0;
			for(int i = 0; i < n; i++){
				count += area[i][j];
			}
			area[n][j] = count;
		}
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				cout << setw(5) << area[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
	int cell[11][11], n;

	while (cin >> n, n){
		for (int i = 0; i < 11; i++){
			for (int j = 0; j < 11; j++){
				cell[i][j] = 0;
			}
		}

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

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

C++: #include<stdio.h>
int main(void)
{
	int n;
	int i,j;
	int data[11][11];
	
	scanf("%d",&n);
	while(n!=0){

		for(j=0;j<=n;j++){
			data[n][j]=0;
		}
		for(i=0;i<n;i++){
			data[i][n]=0;
			for(j=0;j<=n-1;j++){
				scanf("%d",&data[i][j]);
				data[i][n] += data[i][j];
				data[n][j] += data[i][j];
				data[n][n] += data[i][j];
			}
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d ",data[i][j]);
			}
		printf("\n");
		}
	scanf("%d",&n);
	}
	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};
    std::cin.get();
    for(int i=0;i<n;i++){
      std::string s;
      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<iostream>
#include<string>
using namespace std;

int hoge(int w);
int getKetasu(int n);

int main(){
	int w;
	
	while(1){
	 cin>>w;
	 if(w==0){break;}
	 hoge(w);
	}
	
	return 0;
}

int hoge(int w){	//?????£???????????????
	int t[100][100];
	int x,y,i;
	
	for(y=0;y<w;y++){
	 for(x=0;x<w;x++){
	  cin>>t[x][y];
	 }
	}
	
	for(y=0;y<w;y++){
	 t[w][y]=0;
	 for(x=0;x<w;x++){
	  t[w][y]+=t[x][y];
	 }
	}
	for(x=0;x<=w;x++){
	 t[x][w]=0;
	 for(y=0;y<w;y++){
	  t[x][w]+=t[x][y];
	 }
	}
	
	for(y=0;y<=w;y++){
	 for(x=0;x<=w;x++){
	  for(i=getKetasu(t[x][y]);i<5;i++){cout<<" ";}
	  cout<<t[x][y];
	 }
	 cout<<endl;
	}
	
	return 0;
}

int getKetasu(int n){	//?????°?????????
	if(n<10){
	 return 1;
	}else if(n<100){
	 return 2;
	}else if(n<1000){
	 return 3;
	}else{
	 return 4;
	}
}

C++: // #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

void solve(VVI &in, int n){
	int rowSum = 0, columnSum = 0;
	int allSum=0;
	FOR(i, 0, in.size()-1){
		rowSum = 0;
		columnSum = 0;
		FOR(j, 0, in[i].size()-1){
			rowSum += in[i][j];
			columnSum += in[j][i];
		}
		allSum += rowSum;
		in[i][n] = rowSum;
		in[n][i] = columnSum;
	}
	in[n][n] = allSum;
	FOR(i, 0, in.size()){
		FOR(j, 0, in[i].size()){
			printf("%5d", in[i][j]);
			if (j < in[i].size() - 1)
				printf(" ");
		}
		puts("");
	}
}

int main(){
	int n, in = 0;
	while (cin >> n, n){
		VVI inNum(n + 1, VI(n + 1));
		FOR(i, 0, n){
			FOR(j, 0, n){
				cin >> in;
				inNum[i][j] = in;
			}
		}
		solve(inNum,n);
	}
	return 0;
}

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

int main(){
    int n;
    while( cin >> n, n ){
        long long sheet[n+1][n+1];
        int i, j;
        for(i = 0; i < n; i++){
            for(j = 0; j < n; j++){
                cin >> sheet[i][j];
            }
        }
        int ss = 0;
        for(i = 0; i < n; i++){
            int s = 0;
            for(j = 0; j < n; j++){
                s += sheet[i][j];
            }
            sheet[i][n] = s;
            ss += s;
        }
        sheet[n][n] = ss;
        for(i = 0; i < n; i++){
            int s = 0;
            for(j = 0; j < n; j++){
                s += sheet[j][i];
            }
            sheet[n][i] = s;
        }
        for(i = 0; i <= n; i++){
            printf("%5lld", sheet[i][0]);
            for(j = 1; j <= n; j++){
                printf("%5lld", sheet[i][j]);
            }
            cout << endl;
        }
    }
    return 0;
}