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 <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
 
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
  
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
 
int main() {
  int n;
  while(cin >> n, n) {
    int f[12][12] = {};
    rep(i, n) {
      rep(j, n) {
        cin >> f[i][j];
        f[i][n] += f[i][j];
        f[n][j] += f[i][j];
        f[n][n] += f[i][j];
      }
    }
 
    rep(i, n+1) {
      rep(j, n+1) {
        printf("%5d", f[i][j]);
      }
      cout << endl;
    }
  }
}

C++: #include<iostream>
#include<vector>
int main(){
	while(1){
		int a;
		std::cin>>a;
		if(a==0)break;
		std::vector<std::vector<int> > vec(a+1,std::vector<int> (a+1));
		for(int i=0;i<a;i++){
			int b=0;
			for(int j=0;j<a;j++){
				std::cin>>vec[i][j];
				b+=vec[i][j];
			}
			vec[i][a]=b;
		}
		for(int i=0;i<a;i++){
			int c=0;
			for(int j=0;j<a;j++){
				c+=vec[j][i];
			}
			vec[a][i]=c;
		}
		int d=0;
		for(int i=0;i<a;i++){
			d+=vec[a][i];
		}
		vec[a][a]=d;
		for(int i=0;i<a+1;i++){
			for(int j=0;j<a+1;j++){
				if(j==a)std::cout<<vec[i][j];
				else std::cout<<vec[i][j]<<" ";
			}
			std::cout<<std::endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
int main(){
	int n;
	while(std::cin >> n && n){
		std::vector<std::vector<int> > vec(n+1,std::vector<int>(n+1));
		for(int i = 0; i < n; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){
				std::cin>>vec[i][j];
				sum+=vec[i][j];
			}
			vec[i][n]=sum;
		}
		for(int i = 0; i < n+1; ++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+1;++i){
			for(int j = 0; j < n+1; ++j){
				std::cout<<vec[i][j];
				if(j!=n)std::cout<<" ";
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

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

#define BAD "hoshino"

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[w+1][w+1];
	int ketasu;
	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++){
	  if(x!=0){cout<<" ";}
	  ketasu=getKetasu(t[x][w]);
	  for(i=getKetasu(t[x][y]);i<ketasu;i++){cout<<" ";}
	  cout<<t[x][y];
	 }
	}
	
	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++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
 
int ary[10][10];
 
int main() {
        while(1) {
                static int n;
                memset(ary, 0, sizeof(ary));
                scanf(" %d", &n);
                if(!n)
                        break;
                for(int y = 0; y < n; y++) {
                        for(int x = 0; x < n; x++) {
                                static int t;
                                scanf(" %d", &t);
                                ary[y][x] = t;
                        }
                }
                vector<int> width;
                vector<int> height;
                for(int i = 0; i < n; i++) {
                        int sum = 0;
                        for(int j = 0; j < n; j++) {
                                sum += ary[i][j];
                        }
                        width.push_back(sum);
                }
                for(int i = 0; i < n; i++) {
                        int sum = 0;
                        for(int j = 0; j < n; j++) {
                                sum += ary[j][i];
                        }
                        height.push_back(sum);
                }
                int result = accumulate(height.begin(), height.end(), 0);
                
                for(int y = 0; y < n; y++) {
                        for(int x = 0; x < n; x++) {
                                printf("%5d", ary[y][x]);                       
                        }
                        printf("%5d\n", width[y]);
                }
                for(int i = 0; i < n; i++)
                        printf("%5d", height[i]);
                printf("%5d\n", result);
        }
        return 0;
}

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

int main() {
	const int MAX_N = 20;
	int N;
	int table[MAX_N][MAX_N];
	int keta[MAX_N][MAX_N];
	int sum[MAX_N], retu;
	int res;

	while (1) {
		for (int i = 0;i < MAX_N;i++) {
			for (int j = 0;j < MAX_N;j++) {
				table[i][j] = 0;
			}
		}
		cin >> N;
		if (N == 0)break;
		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				cin >> table[i][j];
			}
		}

		for (int i = 0;i < N;i++) {
			for (int j = 0;j < N;j++) {
				keta[i][j] = (int)log10(table[i][j]) + 1;
				table[i][N] += table[i][j];
				table[N][j] += table[i][j];
				table[N][N] += table[i][j];
			}
		}

		for (int i = 0;i <= N;i++) {
			for (int j = 0;j <= N;j++) {
				for (int k = 0;k < 5-(log10(table[i][j])+1);k++) {
					cout << " ";
				}
				cout << table[i][j];
			}
			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 <cstdio>
#include <string>

using namespace std;

int main()
{
    int data[10][10];
    int n;

    while (cin >> n, n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> data[i][j];
            }
        }
        int ans;
        for (int i = 0; i < n; i++) {
            ans = 0;
            for (int j = 0; j < n; j++) {
                printf("%5d", data[i][j]);
                ans += data[i][j];
            }
            printf("%5d\n", ans);
        }
        int s = 0;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += data[j][i];
            }
            printf("%5d", sum);
            s += sum;
        }
        printf("%5d\n", s);
    }
    return 0;
}