Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}

		input := make([][]int, n+1, n+1)
		totalRow := make([]int, n+1, n+1)

		for i := 0; i < n; i++ {
			row := make([]int, n+1, n+1)
			scanner.Scan()

			row = numbers(scanner.Text())

			input[i] = row
			total(totalRow, row)
		}

		input[n] = totalRow

		for xk := range input {
			for yk, yv := range input[xk] {
				if yk == n {
					fmt.Printf("%5d\n", yv)
				} else {
					fmt.Printf("%5d", yv)
				}
			}
		}
	}
}

func total(sum, row []int) {
	for i := 0; i < len(row); i++ {
		sum[i] += row[i]
	}
}

func numbers(s string) []int {
	var n []int
	var sum int
	for _, f := range strings.Fields(s) {
		i, err := strconv.Atoi(f)
		if err == nil {
			n = append(n, i)
			sum += i
		}
	}
	n = append(n, sum)
	return n
}

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

int main(){
	int n;
	while(cin >> n){
		if(n == 0) break;
		else{
			int data[n+2][n+2] = {0};

			for (int i = 0; i < n+2; ++i){
				for(int j = 0; j < n+2; j++){					
				data[i][j] = 0;
				}
			}
			
			for (int i = 0; i < n; ++i){
				for(int j = 0; j < n; j++){					
				cin >> data[i][j];
				}
			}
			for (int i = 0; i < n; ++i){
				for(int j = 0; j < n; j++){	
					data[i][n] += data[i][j];
				}
			}
			for (int i = 0; i < n+1; ++i){
				for(int j = 0; j < n; j++){	
					data[n][i] += data[j][i];
				}
			}
			for (int i = 0; i < n+1; ++i){
				for(int j = 0; j < n+1; j++){
					cout << data[i][j];
					if (j != n) cout<<" ";
				}
				cout << endl;
			}
				
		}
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n,x[101][101],i,j,sum;
	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;
		}
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%d ",x[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

C++: #include<iostream>


using namespace std;


int main(){
	int a[10][10];
	int d, i, j, k, temp,sum=0;

	while (1){
		cin >> d;
		if (d == 0){
			return 0;
		}

		for (i = 0, j = 0; i < d; i++){
			for (j = 0; j < d; j++){
				cin >> a[i][j];
			}
		}

		for (i = 0, j = 0; i < d; i++){
			for (j = 0; j < d; j++){
				cout.width(5);
				cout << a[i][j];
			}
			temp = 0;
			for (k = 0; k < d; k++){
				temp += a[i][k];
			}
			cout.width(5);
			cout << temp << endl;
			sum += temp;
		}
			
		

		for (j = 0; j < d; j++){
			temp = 0;
			for (k = 0; k < d; k++){
				temp += a[k][j];
			}
			cout.width(5);
			cout << temp;
			sum += temp;

		}



		cout.width(5);
		cout << sum/2 << endl;
		sum = 0;
	}
}

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

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

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

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

using namespace std;

int h[12][12];
int n;
int sum[2][12];

int main()
{
  while(true)
  {
    for(int i = 0; i < 12; i++)
    {
      for(int j = 0; j < 12; j++)
        h[i][j] = 0;
    }
    scanf("%d", &n);
    if(!n)
      break;
    for(int i = 0; i < n; i++)
    {
      for(int j = 0; j < n; j++)
        scanf("%d", &h[i][j]);
    }
    for(int i = 0; i <= n; i++)
    {
      for(int j = 0; j <= n; j++)
      {
        printf("%5d", h[i][j]);
        h[i][n] += h[i][j];
        if(j != n)
        h[n][j] += h[i][j];
      }
      printf("\n");
    }
  }
  return 0;
}

C++: #include <stack>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <utility>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int main() {
    
    int n;
    while(cin >> n && n != 0)
    {
        int a[11][11];
        for(int i = 0;i < n;i++)
        {
            for(int j = 0; j<n;j++)
            {
                cin >> a[i][j];
            }
        }
        for(int i = 0; i<n;i++)
        {
            a[i][n] = 0;
            a[n][i] = 0;
            for(int j = 0;j < n;j++)
            {
                a[i][n] += a[i][j];
                a[n][i] += a[j][i];
            }
        }
        a[n][n] = 0;
        for(int i = 0;i<n;i++)
        {
            a[n][n] += a[i][n];
        }
        for(int i = 0; i< n+1;i++)
        {
            for(int j = 0; j<n+1;j++)
            {
                cout << setw(5) << right << a[i][j];
            }
            cout <<endl;
        }
    }
    return 0;
}

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

using namespace std;

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