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>
using namespace std;
int main()
{
    while(1)
    {
        int n;
        cin>>n;if(!n)return 0;
        int t[11][11]={{0}};
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                cin>>t[i][j];
            }
        }
        for(int i=0;i<n;++i){
            int sum=0;
            for(int j=0;j<=n;++j){
                if(j!=n){
                    sum+=t[i][j];
                    t[n][n]+=t[i][j];
                }
                if(j==n){
                    t[i][j]=sum;
                }
            }
        }
        for(int j=0;j<n;++j){
            int sum=0;
            for(int i=0;i<=n;++i){
                if(i!=n){
                    sum+=t[i][j];
                }
                if(i==n){
                    t[i][j]=sum;
                }
            }
        }
        for(int i=0;i<=n;++i){
            for(int j=0;j<=n;++j){
                printf("%5d",t[i][j]);
            }
            cout<<endl;
        }
    }
}

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

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int table[20][20];
		for(int i = 0; i < n; i++){
			int sum=0;
			for(int j = 0; j < n; j++){
				cin>>table[i][j];
				sum+=table[i][j];
			}
			table[i][n]=sum;
		}
		for(int j = 0; j <= n; j++){
			//table[n]
			int sum=0;
			for(int i = 0; i < n; i++){
				sum+=table[i][j];
			}
			table[n][j]=sum;
		}
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				printf("%5d",table[i][j]);
			}
			cout<<endl;
		}
	}

	return 0;
}

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

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

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

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int table[11][11]={0};
		if(n==0)break;
		for(int i=0,in;i<n;++i){
			for(int j=0;j<n;++j){
				cin>>in;
				table[i][j]=in;
				table[n][j]+=in;
				table[i][n]+=in;
			}
		}
		for(int i=0;i<n;++i)table[n][n]+=table[n][i];
		for(int i=0;i<n+1;++i){
			for(int j=0;j<n+1;++j)printf("%5d",table[i][j]);
			cout<<"\n";
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,i,j,t,ans1=0,ans2=0,ans3=0,list[100][100]={2};
  while(1){
  cin >> n;
  if(n==0){
    break;
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      cin >> list[i][j];
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      ans1=ans1+list[i][j];
      ans2=ans2+list[j][i];
    }
    list[i][j]=ans1;
    ans3=ans3+ans1;
    ans1=0;
    list[j][i]=ans2;
    ans2=0;
  }
  list[i][j]=ans3;
  ans3=0;
  for(i=0;i<n+1;i++){
    for(j=0;j<n+1;j++){
      printf("%5d",list[i][j]);
    }
    cout << endl;
  }
  }
  return (0);
}

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

int main(){
	while(1){
		int n;
		int map[11][11];
		int row[11];
		int line[11];
		int allSum = 0;
		scanf("%d", &n );
		if( n == 0 ) break;

		for( int y=0; y<n; y++ ){
			for( int x=0; x<n; x++ ){
				scanf("%d", &map[x][y]);
			}
		}
		for( int y=0; y<n; y++ ){
			line[y] = 0;
			for( int x=0; x<n; x++ ){
				line[y] += map[x][y];
			}
		}
		for( int x=0; x<n; x++ ){
			row[x] = 0;
			for( int y=0; y<n; y++ ){
				row[x] += map[x][y];
			}
		}
		for( int i=0; i<n; i++ ){
			allSum += row[i];
		}
		for( int y=0; y<n; y++ ){
			for( int x=0; x<n; x++ ){
				printf("%5d", map[x][y]);
			}
			printf("%5d\n", line[y] );
		}
		for( int x=0; x<n; x++ ){
			printf("%5d", row[x]);
		}
		printf("%5d\n", allSum );
	}
	return 0;
}

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

int main()
{
	int n,sum,i,sumsum=0;
	int array[11]={0};
	while(1){
		for(i=0;i<11;i++) array[i]=0;
		cin >> n;
		int loop = n;
		if(!n)break;
		while(loop--){
			sum = 0;
			for(i=0;i<n;i++){
				int x;
				cin >> x;
				cout << setw(5) << x;
				sum += x;
				array[i] += x;
			}
			cout << setw(5) << sum << "\n";
		}
		for(i=0;i<n;i++){
			cout << setw(5) << array[i];
			sumsum += array[i];
		}
	cout << setw(5) << sumsum << "\n";
	sumsum=0;
	}
	return 0;
}

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

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector< vector<int> > mat(n + 1, vector<int>(n + 1));
		for(int i = 0; i < n; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){
				cin >> mat[i][j];
				sum += mat[i][j];
			}
			mat[i][n] = sum;
		}
		for(int i = 0; i <= n; ++i){
			int sum = 0;
			for(int j = 0; j < n; ++j){ sum += mat[j][i]; }
			mat[n][i] = sum;
		}
		for(int i = 0; i <= n; ++i){
			for(int j = 0; j <= n; ++j){
				printf("%5d", mat[i][j]);
			}
			puts("");
		}
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int n, j, i;
	int mat[15][15];
	
	while(1){
		scanf("%d", &n);
		
		if (n == 0) break;
		
		
		for (i = 0; i <= n; i++){
			for (j = 0; j <= n; j++){
				mat[i][j] = 0;
			}
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				scanf("%d", &mat[i][j]);
				mat[i][n] += mat[i][j];
			}
		}
		
		for (i = 0; i <= n; i++){
			for (j = 0; j < n; j++){
				mat[n][i] += mat[i][j];
			}
		}
		
		for (i = 0; i <= n; i++){
			for (j = 0; j <= n; j++){
				printf("%5d", mat[i][j]);
			}
			puts("");
		}
	}
	return (0);
}

C++: #include <algorithm>
#include <cmath>
#include <ctime>
#include <climits>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    while (cin >> n && n) {
        vector<vector<int>> mat(n+1, vector<int>(n+1, 0));
        for (int i=0; i<n; ++i) {
            for (int j=0; j<n; ++j) {
                cin >> mat[i][j];
                mat[n][j] += mat[i][j];
                mat[i][n] += mat[i][j];
                mat[n][n] += mat[i][j];
            }
        }
        for (int i=0; i<n+1; ++i) {
            for (int j=0; j<n+1; ++j) {
                cout << (j == 0 ? "" : " ") << mat[i][j];
            }
            cout << endl;
        }
    }

    return 0;
}