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>

using namespace std;

int matrix[11][11];

int main()
{
	int n,sum;
	
	for(;;)
	{
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cin>>matrix[i][j];
			}
		}

		for(int i=0;i<n;i++)
		{
			sum=0;
			for(int j=0;j<n;j++)
			{
				sum+=matrix[i][j];
			}
			matrix[i][n]=sum;
		}
		for(int j=0;j<n;j++)
		{
			sum=0;
			for(int i=0;i<n;i++)
			{
				sum+=matrix[i][j];
			}
			matrix[n][j]=sum;
		}
		sum=0;
		for(int i=0;i<n;i++)
		{
			sum+=matrix[i][n];
		}
		matrix[n][n]=sum;
		
		for(int i=0;i<=n;i++)
		{
			for(int j=0;j<=n;j++)
			{
				if(j>0)cout<<' ';
				cout<<setfill(' ')<<setw(5)<<right<<matrix[i][j];
			}
			cout<<endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n, n) {
		int data[150][150] = { 0 };

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

		}
		for (int i = 0;i < n+1;i++) {
			for (int j = 0;j < n+1;j++) {
				cout << data[i][j]<<" ";
			}
			cout << endl;
		}
		

	}
	return 0;

}

C++: #include <stdio.h>

int main(void)
{
	int a[1000][1000] = {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");
		}
		
		scanf("%d", &n);
	}

	return 0;
}

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

int main(){
	int n;
	do	{
		int** Mat;
		cin >> n;
		if (n == 0){
			break;
		}
		Mat = new int*[n];
		for (int i = 0; i < n; i++){
			Mat[i] = new int[n];
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> Mat[i][j];
			}
		}

		int sumrow;
		int* sumcol;
		sumcol = new int[n]();
		int sum = 0;

		for (int i = 0; i < n; i++){
			sumrow = 0;
			for (int j = 0; j < n; j++){
				cout.width(5);
				cout << Mat[i][j];
				sumrow += Mat[i][j];
				sumcol[j] += Mat[i][j];
			}
			cout.width(5);
			cout << sumrow << endl;
		}
		for (int j = 0; j < n; j++){
			cout.width(5);
			cout << sumcol[j];
			sum += sumcol[j];
		}
		delete[] sumcol;
		cout.width(5);
		cout << sum << endl;



		//行列delete
		for (int i = 0; i < n; i++){
			delete[] Mat[i];
		}
		delete[] Mat;
	} while (n != 0);

}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include<iomanip>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(s) (s).begin(),(s).end()
#define ITE(c) typeof((c).begin())

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

using namespace std;

int main(){
	int dat[16][16];
	int n;
	while(cin>>n,n){
		rep(i,n){
			rep(j,n){
				dat[j][i]=0;
			}
		}
		int ssum=0;
		rep(i,n){
			int sum=0;
			rep(j,n){
				cin>>dat[j][i];
				sum+=dat[j][i];
			}
			ssum+=sum;
			dat[n][i]=sum;
		}
		dat[n][n]=ssum;
		rep(i,n){
			int sum=0;
			rep(j,n){
				sum+=dat[i][j];
			}
			dat[i][n]=sum;
		}
		rep(i,n+1){
			rep(j,n){
				cout<<setw(5)<<dat[j][i];
			}
			cout<<setw(5)<<dat[n][i]<<endl;
		}
	}
	return 0;
}

C++: #include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>

typedef long long ll;

int r[101][101] = {0};

using namespace std;

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


	return 0;
}

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

using namespace std;

int main()
{
	int n;
	int i,j;
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		int table[12][12]={0};
		
		for(i=0;i<n;i++)
		{
			for(j=0;j<n;j++)
			{
				cin >> table[i][j] ;
			}
		}
		
		for(i=0;i<=n;i++)
		{
			for(j=0;j<=n;j++)
			{
				if(j!=n)
				{
					printf("%5d ",table[i][j]);
					table[i][n]+=table[i][j];
					table[n][j]+=table[i][j];
				}
				else
					printf("%5d",table[i][j]);
			}
			cout << endl;
		}
	}
}

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

int main(){
	int data[11][11];
	int n;
	cin >> n;
	while (n){

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				cin >> data[i][j];
			}
		}
		int sum_col[10] = { 0 };
		int sum_low[10] = { 0 };

		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				sum_col[i] += data[i][j];
				sum_low[i] += data[j][i];
			}
			data[i][n] = sum_col[i];
			data[n][i] = sum_low[i];
		}
		int sum = 0;
		for (int i = 0; i < n; i++){
			sum += data[i][n];
		}
		data[n][n] = sum;
		for (int i = 0; i < n + 1; i++){
			for (int j = 0; j < n + 1; j++){
				cout << setw(5) << right << data[i][j];
			}
			if (i != n)	cout<<"\n";
		}
		cin >> n;
		if (n) cout<<"\n";
	}
	
	return 0;	
}