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 <iomanip>
#include <vector>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;

#define REP(i, m, n) for (int i = static_cast<int>(m); i < static_cast<int>(n); ++i)

int main()
{
    
    

    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) break;
        
        VVI vvi;

        REP(i, 0, n) {
            vvi.push_back( vector<int>() );
            int sum = 0;
            
            REP(j, 0, n) {
                int in;
                std::cin >> in;
                vvi[i].push_back(in);
                sum += in;
            }
            vvi[i].push_back(sum);
        }

        vvi.push_back( vector<int>() );
        REP(i, 0, n + 1) {
            int sum = 0;
            
            REP(j, 0, n) {
                sum += vvi[j][i];
            }
            
            vvi[n].push_back(sum);
        }
        
        std::cout << "hoge" << std::endl;
        REP(i, 0, vvi.size()) {
            REP(j, 0, vvi[i].size()) {
                std::cout << std::setw(5) << vvi[i][j];
            }
            std::cout << std::endl;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,c;
  while(cin>>n,n){
    int a[n+1][n+1];
    rep(i,n){c=0;rep(j,n){
        cin>>a[i][j];
        c+=a[i][j];
      }
      a[i][n]=c;
    }
    rep(j,n+1){c=0;rep(i,n){
      c+=a[i][j];
    }
    a[n][j]=c;
  }
  rep(i,n+1){rep(j,n+1){printf("%5d",a[i][j]);}cout<<endl;}
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int n;
	while(cin>>n,n) 
	{
		int f[n+1][n+1];
		memset(f,0,sizeof(f));
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				cin>>f[i][j];
				f[i][n]+=f[i][j];
				f[n][j]+=f[i][j];
				f[n][n]+=f[i][j];
			}
		}
		for(int i = 0; i <= n; ++i)
		{
			for(int j = 0; j <= n; ++j)
			{
				printf("%5d",f[i][j]);
			}
			cout<<endl;
		}
	}
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<set>
#include<iomanip>
int elem[10][10];
using namespace std;

int main() {
	int n; 
	while(cin >> n, n != 0){
		int allsum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> elem[i][j];
				allsum += elem[i][j];
			}
		}
		elem[n][n] = allsum;
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += elem[i][j];
			}
			elem[i][n] = sum;
		}
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += elem[j][i];
			}
			elem[n][i] = sum;
		}
		
		for(int i=0; i<=n; i++){
			for (int j = 0; j <= n; j++) {
				cout << setw(5) << elem[i][j];
			}cout << endl;
		}
	}
	return 0;
}

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

int main(){
    int number;
    int sum = 0;
    
    while(1){
        cin >> number;
        if (number == 0){
            break;
        }
        
       
        int array[number][number];
        int lastColumn[number];
        int lastRow[number];
        int total=0;
        
        for(int i=0; i<number; i++){
            sum = 0;
            for(int j=0; j<number; j++){
                cin >> array[i][j];
                sum += array[i][j];
            }
            lastColumn[i] = sum;
        }
        
        for(int j=0; j<number; j++){
            sum = 0;
            for(int i=0; i<number; i++){
                sum += array[i][j];
            }
            lastRow[j] = sum;
            total +=sum;
        }
        
        for(int i=0; i<number; i++){
            for(int j=0; j<number; j++){
                printf("%5d", array[i][j]);
            }
            cout << lastColumn[i] <<"\n";
        }
        
        for(int i=0; i<number; i++){
            printf("%5d", lastRow[i]);
         }
        printf("%5d\n", total);

    }
    
    return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int ct,map[10][10],answer[11][11];
	while(1){
		scanf("%d",&ct);
		if(ct==0){
			return 0;
		}
		for(int f1=0;f1<11;f1++){
			for(int f2=0;f2<11;f2++){
				answer[f1][f2]=0;
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				scanf("%d",&map[f1][f2]);
				answer[f1][f2]=map[f1][f2];
			}
		}
		for(int f1=0;f1<ct;f1++){
			for(int f2=0;f2<ct;f2++){
				answer[f1][ct]+=map[f1][f2];
				answer[ct][f1]+=map[f2][f1];
			}
		}
		for(int f1=0;f1<ct;f1++){
			answer[ct][ct]+=answer[f1][ct];
		}
		for(int f1=0;f1<ct+1;f1++){
			for(int f2=0;f2<ct+1;f2++){
				printf("%5d ",answer[f1][f2]);
			}
			printf("\n");
		}
	}
	return 0;
}

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

using namespace std;

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

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

		nums[n][n] = 0;
		for (int i = 0; i < n; ++i)
			nums[n][n] += nums[i][n];

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

C++: #include <iostream>
using namespace std;
int main()
{
	int n, num[11][11];
	while (1) {
		if (cin >> n, !n) break;
		for (int i=0; i<11; i++) for (int j=0; j<11; j++) num[i][j] = 0;
		for (int i=0; i<n; i++)  for (int j=0; j<n; j++) cin >> num[i][j];
		for (int i=0; i<10; i++) for (int j=0; j<10; j++) num[10][i] += num[j][i];
		for (int i=0; i<11; i++)
			for (int j=0; j<10; j++) num[i][10] += num[i][j];

		for (int i=0; i<11; i++) {
			for (int j=0; j<11; j++) {if ((i<n && j<n) || (i==10 && j<n) || (j==10 && i<n) || (j==10 && i==10)) {cout.width(5); cout << num[i][j];}}
			if ((i < n) || (i == 10))  cout << endl;
		}
	}

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

int main(){
	int n;
	while(1){
		cin>>n;
		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];
			}
			cout<<endl;
		}
	}
	return 0;
}