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<cstring>
#include<numeric>

int d[11][11];

int main(){
  int n;
	while( std::cin>>n , n ){
		memset(d,0,sizeof(d));
		for( int i=0; i<n; ++i ){
		  for( int l=0; l<n; ++l ){
			  std::cin>> d[l][i];
			}
		}
		for(int i=0; i<=n; ++i){
			for(int l=0;l<=n; ++l){
			  if(l==n && i!=n){
					for( int m=0;m<n;++m )
						d[l][i]+=d[m][i];
					std::cout.width(5);
					std::cout<<d[l][i]<<std::endl;
				}else{
					if(i==n){std::cout.width(5);std::cout<<std::accumulate(d[l],d[l]+n,0)<<(l!=n?"":"\n");}
					else{std::cout.width(5);std::cout<<d[l][i];}
				}
			}
		}
	}
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
	int ta[100][100],sum[100];
	int n,all;
	while(cin>>n,n){
	all=0;
	for(int i=0;i<100;i++)sum[i]=0,fill(ta[i],ta[i]+100,0);
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>ta[i][j];
	for(int i=0;i<n;i++){
		int tnow=0;
		for(int j=0;j<n;j++){
			string ss=itos(ta[i][j]);
			if(j==0)for(int i=0;i<5-ss.size();i++)cout<<" ";	
		cout<<ta[i][j];
	for(int i=0;i<5-ss.size();i++)cout<<" ";

		sum[j]+=ta[i][j];
		tnow+=ta[i][j];
		all+=ta[i][j];
		}
		cout<<tnow<<endl;
	}
	for(int i=0;i<n;i++){
	string ss=itos(sum[i]);
	if(i==0)for(int i=0;i<5-ss.size();i++)cout<<" ";
	cout<<sum[i];

	for(int i=0;i<5-ss.size();i++)cout<<" ";
	}
	cout<<all<<endl;
	}

	return 0;
}

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

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

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

int main(){
	int n;
	while(cin >> n,n){
		int data[10+1][10+1];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}

		int all_sum = 0;

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




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


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

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

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

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

int main()
{
	int n, i, j;
	vector< vector<int> > list(11, vector<int>(11));
	while (cin>>n, n) {
		for (i = 0; i <= n; i++) {
			list[i][n] = 0;
			list[n][i] = 0;
		}
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				cin>>list[i][j];
				list[i][n] += list[i][j];
				list[n][j] += list[i][j];
				list[n][n] += list[i][j];
			}
		}
		for (i = 0; i <= n; i++) {
			for (j = 0; j <= n; j++) {
				if (j != 0) cout<<" ";
				cout<<setw(5)<<right<<list[i][j];
			}
			cout<<endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
int main(){
	int n,i,j;
	while(1){
		int matrix[11][11]={0};
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&matrix[i][j]);
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				matrix[n][j] += matrix[i][j];
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<=n;j++){
				matrix[j][n] += matrix[j][i];
			}
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d",matrix[i][j]);
			}
			printf("\n");
		}
	}
	return (0);
}

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

int main(){
    int n;
    while(1){
      int sum = 0, s = 0;
      cin >> n;
      if( n == 0) break;
      int poi[n][n];
      for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
         cin >> poi[i][j];
         sum += poi[i][j];
      }
    }
    for(int i = 0;i < n;++i){
    	for(int j = 0;j < n;++j){
    		cout << poi[i][j] << "  ";
    		s += poi[i][j];
    		if(j == n -1){
    			cout << " " << s << endl;
    			s = 0;
    		}
    	}
    }
    for(int i = 0;i < n;++i){
    	for(int j = 0;j < n;++j){
    		cout << poi[j][i] << "  ";
    	}
    }
    cout << " " << sum << endl;
   }
  return 0;
}

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

vector<vector<int> > v;

int main(){
  int n;
  while(true){
    cin>>n;
    if(n==0)break;
    v.clear();
    for(int i=0; i<n; i++){
      vector<int> tmp;
      for(int j=0; j<n; j++){
        int c;
        cin>>c;
        tmp.push_back(c);
      }
      v.push_back(tmp);
    }
    //行方向
    for(int i=0; i<n; i++){
      int sum=0;
      for(int j=0; j<n; j++)sum+=v[i][j];
      v[i].push_back(sum);
    }
    //列方向
    vector<int> tmp;
    for(int j=0; j<n; j++){
      int sum=0;
      for(int i=0; i<n; i++)sum+=v[i][j];
      tmp.push_back(sum);
    }
    int sum=0;
    for(int i=0; i<n; i++)sum+=tmp[i];
    tmp.push_back(sum);
    v.push_back(tmp);
    for(int i=0; i<=n; i++){
      for(int j=0; j<=n; j++){
        printf("%5d", v[i][j]);
      }
      cout<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;



int main(void){

string ws;
int n;
	while(cin >> n){
		if(n==0 || cin.eof()) break;
		vector<vector<int> > hg(n+1,vector<int>(n+1,0));
		rep(i,n) rep(j,n) cin >> hg[i][j];
		rep(i,n) rep(j,n){
			hg[n][i] += hg[j][i];
			hg[i][n] += hg[i][j];
		}
		rep(i,n) hg[n][n] += hg[i][n];
		rep(i,n+1){
			rep(j,n+1) printf("%5d",hg[i][j]);
			printf("\n");
		}
	}
	return 0;
	
}