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<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 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++){
		cout<<ta[i][j]<<" ";
		sum[i]+=ta[i][j];
		tnow+=ta[i][j];
		all+=ta[i][j];
		}
		cout<<tnow<<endl;
	}
	for(int i=0;i<n;i++)cout<<sum[i]<<" ";
	cout<<all<<endl;
	}

	return 0;
}

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

int main(){
	int n;
	while(1){
	cin>>n;
		if(n==0)break;
	vector<vector<int> > a(n+1,vector<int>(n+1));
	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++){
		int b=0;
		for(int j=0;j<n;j++){
			cout<<"  "<<a[i][j]<<" ";
			b+=a[i][j];
		}
		cout<<b<<endl;
	}
	
	int d=0;
	
	for(int i=0;i<n;i++){
		int c=0;
		for(int j=0;j<n;j++){
			c+=a[j][i];
		}
		cout<<" "<<c<<" ";
		d+=c;
	}
	cout<<d<<endl;
	}
	return 0;
}

C++: #include <stdio.h>

int main(void)
{
	int a[11][11] = {0};
	int n, i, j;

	scanf("%d", &n);
	while (n != 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];
			a[n][n] += a[i][n];
		}

		for (j = 0; j < n; j++)
			for (i = 0; i < n; i++)
				a[n][j] += a[i][j];

		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<cstdio>

using namespace std;

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

}

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

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		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];
				else if(dt[a][b]/10000==0)cout<<" "<<dt[a][b];
				else if(dt[a][b]/100000==0)cout<<dt[a][b];
			}
			cout<<endl;
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#define rep(i, n) for(i=0;i<(n);++i)
int a[11][11], n, i, j, t;
int main()
{
    while (scanf("%d", &n), n) {
        memset(a, 0, sizeof(a));
        rep(i, n) rep(j, n) {
            scanf("%d", &t); a[i][j] = t; a[n][j] += t; a[i][n] += t;
        }
        rep(i, n) a[n][n] += a[i][n];
        rep(i, n+1) {
            rep(j, n+1) printf("%5d", a[i][j]);
            puts("");
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n;
int tb[11][11];

int main() {
	while (1) {
		cin >> n; if (n == 0) break;
		
		int allsum = 0;
		for (int i = 0; i < n; i++) {
			int rsum = 0;
			for (int j = 0; j < n; j++) {
				cin >> tb[i][j];
				rsum += tb[i][j];
			}
			tb[i][n] = rsum;
			allsum += rsum;
		}
		tb[n][n] = allsum;
		
		for (int j = 0; j < n; j++) {
			int csum = 0;
			for (int i = 0; i < n; i++) {
				csum += tb[i][j];
			}
			tb[n][j] = csum;
		}
		
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				cout << setw(5) << tb[i][j];
			}
			cout << endl;
		}
	}	
	
	return 0;
}

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

int main(void){
  int n;
  int tmp;

  while(cin >> n && n){
	int colsum[n+1];

	memset(colsum, 0, sizeof(colsum));
	for(int i=0;i<n;i++){
	  int sum=0;
	  for(int j=0;j<n;j++){
		cin >> tmp;
		printf("%5d", tmp);
		sum += tmp;
		colsum[j] += tmp;
	  }
	  printf("%5d\n", sum);
	  colsum[n] += sum;
	}
	for(int i=0;i<n+1;i++){
	  if(i!=n){
		printf("%5d", colsum[i]);
	  }else{
		printf("%5d\n", colsum[i]);
	  }
	}
  }
  
}

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

#define MAX_N 10

int a[MAX_N+1][MAX_N+1];
int n;

void solve() {
    // row sum
    for (int i=0; i<n; i++) {
        a[i][n] = 0;
        for (int j=0; j<n; j++) {
            a[i][n] += a[i][j];
        }
    }
    // column sum
    for (int j=0; j<n; j++) {
        a[n][j] = 0;
        for (int i=0; i<n; i++) {
            a[n][j] += a[i][j];
        }
    }
    // total sum
    a[n][n] = 0;
    for (int i=0; i<n; i++) a[n][n] += a[i][n];

    // output
    for (int i=0; i<n+1; i++) {
        for (int j=0; j<n+1; j++) {
            std::cout << std::setw(5) << a[i][j];
        }
        std::cout << std::endl;
    }
}

int main() {
    while(std::cin >> n, n) {
        for (int i=0; i<n; i++) {
            for (int j=0; j<n; j++) {
                std::cin >> a[i][j];
            }
        }
        solve();
    }
}

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

int main()
{
	int n;

	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++){
			int num, sum = 0;
			for (int j = 0; j < n; j++){
				scanf("%d", &num);
				sum += num;
				printf("%5d", num);
			}
			printf("%5d\n", sum);
		}
	}

	return (0);
}

C++: #include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	for (int i = 0; i < 100; i++)
	{
		int n,a[100][100];
		cin >> n;
		if (n == 0)
		{
			break;
		}

		for (int j = 0; j < n; j++)
		{
			for (int k = 0; k < n; k++)
			{
				cin >> a[j][k];
			}
		}
		int co = 0;
		int coo = 0;

		for (int j = 0; j < n; j++)
		{
			for (int k = 0; k < n; k++)
			{
				co += a[j][k];
			}
			a[j][n] = co;
			co = 0;
		}

		for (int k = 0; k < n + 1; k++)
		{
			for (int j = 0; j < n; j++)
			{
				coo += a[j][k];
			}
			a[n][k] = coo;
			coo = 0;
		}



		for (int j = 0; j < n + 1; j++)
		{
			for (int k = 0; k < n + 1; k++)
			{
				ostringstream p;
				string pp;
				p << a[j][k];
				pp = p.str();
				int l = 0;
				l = pp.size();
				if (l == 1)
				{
					cout << "    ";
				}
				else if (l == 2)
				{
					cout << "   ";
				}
				else if (l == 3)
				{
					cout << "  ";
				}
				else if (l == 4)
				{
					cout << " ";
				}
				cout << a[j][k];
			}
			cout << endl;
		}
	}
}