Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	out := make([][]string, 100)
	for i := range out {
		out[i] = make([]string, 100)
	}
	dx := []int{0, 1, 0, -1}
	dy := []int{-1, 0, 1, 0}
	scanner.Scan()
	a, _ := strconv.Atoi(scanner.Text())
	for a > 0 {
		a--
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < b; i++ {
			for j := 0; j < b; j++ {
				out[i][j] = " "
			}
			out[i][b] = "0"
		}
		if b == 1 {
			fmt.Println("#")
			if a != 0 {
				fmt.Println()
			}
			continue
		}
		if b == 2 {
			fmt.Println("##")
			if a != 0 {
				fmt.Println()
				continue
			}
		}
		row := b -1
		col := 0
		dir := 0
		l := 0
		out[row][col] = "#"
		for {
			nrow := row+dy[dir%4]
			ncol := col+dx[dir%4]
			if dir%4 == 0 && nrow == 0 || dir%4==3&&ncol==0 || dir%4==2&&nrow==b-1 || dir%4==1&&ncol==b-1 {
				row=nrow
				col=ncol
				out[row][col]="#"
				dir++
				l = 1
			} else if out[nrow+dy[dir%4]][ncol+dx[dir%4]]=="#" {
				if l < 3 {
					break
				}
				dir++
				l = 1
			} else {
				row=nrow
				col=ncol
				out[row][col]="#"
				l++
			}
		}
		for i := 0; i < b; i++ {
			for j := 0; j < b; j++ {
				fmt.Printf("%s", out[i][j])
			}
			fmt.Println()
		}
		if a != 0 {
			fmt.Println()
		}
	}
}

C++: #include <cstdio>

#define MAX 150

char sp[MAX][MAX];
//u r d l
const int dx[] = {0,1,0,-1};
const int dy[] = {-1,0,1,0};

bool range(int x,int y,int n){
  if(0 > x || x >= n || 0 > y || y >= n){
    return false;
  }
  return true;
}

void make(int n){
  int x = 0 , y = n-1 ,dir = 0;

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

  int end = 0;
  sp[y][x] = '#';
  while(true){
    int nx = x + dx[dir];
    int ny = y + dy[dir];  

    bool flg = true;
    if(!range(nx,ny,n)){
      flg = false;
    }

    for(int i = 0 ; i < 4 ; i++){
      int nnx = nx + dx[i];
      int nny = ny + dy[i];

      if((x == nnx && y == nny) 
	 || !range(nnx,nny,n)){
	continue;
      }

      if(sp[nny][nnx] == '#'){
	flg = false;
	break;
      }
    }

    if(!flg){
      dir++;
      dir = dir % 4;
      end++;
      if(end == 4) return;
    }else{
      end = 0;
    }

    if(flg){
      sp[ny][nx] = '#';
      x = nx;
      y = ny;
    }
  }
}

int main(){
  int d,n;

  scanf("%d" ,&d);
  while(d--){
    scanf("%d" ,&n);

    make(n);
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
	if(sp[i][j] == '.'){
	  printf(" ");
	}else{
	  printf("%c" ,sp[i][j]);
	}
      }
      puts("");
    }   
  }

  return 0;
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

bool range(int n, int x, int y)
{
	return 0 <= x && x < n && 0 <= y && y < n;
}
void rec(vector<vector<char> >& g, int x, int y, int dx, int dy, int c)
{	
	int n = g.size();
	if(c == 4) return;
	
	g[x][y] = '#';

	int nx = x + dx, ny = y + dy;
	if(range(n, nx, ny) && g[nx][ny] != '#' && (range(n, nx + dx, ny + dy) ? g[nx + dx][ny + dy] != '#' : true))
	{
		rec(g, nx, ny, dx, dy, 0);
	}
	else
	{
		if(dx == 0 && dy == -1) 	rec(g, x, y,  1, 0, c + 1);
		else if(dx == 1 && dy == 0)	rec(g, x, y,  0, 1, c + 1);
		else if(dx == 0 && dy == 1)	rec(g, x, y, -1, 0, c + 1);
		else						rec(g, x, y, 0, -1, c + 1);
	}
}

int main()
{
	int d;
	cin >> d;
    
	for(int n; d && cin >> n; d--)
	{
		vector<vector<char> > g(n, vector<char>(n, ' '));
		
		rec(g, 0, n - 1, 0, -1, 0);
		
		if(n % 2 == 0) g[n / 2][n / 2] = ' ';
		
		rep(y, n) rep(x, n) cout << g[x][y] << (x + 1 == n ? "\n" : "");
	}
}

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

using namespace std;

const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};

inline void next(int &d)
{
    d = (d + 1) % 4;
}

int main()
{
    int dataset, n;

    cin >> dataset;
    while (dataset--) {
        cin >> n;

        vector<vector<bool> > map(n, vector<bool>(n, false));
        int d = 0, x = 0, y = n - 1, l = n - 1;

        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < l; ++j) {
                map[y][x] = true;
                x += dx[d];
                y += dy[d];
            }
            next(d);
        }

        l -= 2;
        map[y][x] = true;
        for (int i = 0; i < n / 2; ++i) {
            for (int j = 0; j < l; ++j) {
                map[y][x] = true;
                x += dx[d];
                y += dy[d];
            }
            if (i % 2 != 0)
                l -= 2;
            map[y][x] = true;
            next(d);
         }

        // Output
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                if (map[i][j])
                    cout << "#";
                else
                    cout << " ";
            }
            cout << "\n";
        }
    }

    return 0;
}

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

bool field[100][100];

void migi(int y,int x,int j)
{
	for(int i=1;i<=j;i++){
		field[y][x+i] = 1;
	}
}
void sita(int y,int x,int j)
{
	if(j <= 1)
		return;
	for(int i=1;i<=j;i++){
		field[y+i][x] = 1;
	}
}
void hidari(int y,int x,int j)
{
	for(int i=1;i<=j;i++){
		field[y][x-i] = 1;
	}
}
void ue(int y,int x,int j)
{
	if(j <= 1)
		return;
	for(int i=1;i<=j;i++){
		field[y-i][x] = 1;
	}
}	
int main()
{
	int a;
	cin >> a;
	for(int i=0;i<a;i++){
		int n;
		cin >> n;
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				field[j][k] = 0;
			}
		}
		int y=n-1,x=0;
		for(int j=0;j<n;j++){
			field[y-j][x] = 1;
		}
		y = 0;
		
		for(int j=n-1;j>=0;j-=2){
			migi(y,x,j);
			x = x+j;
			sita(y,x,j);
			y = y+j;			
			j-=2;
			hidari(y,x,j);
			x = x-j;
			ue(y,x,j);
			y = y-j;
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(field[i][j] == 1)
					cout << "#";
				else
					cout << " ";
			}
			cout << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int j = 0; j < n; j++) {
		int a;
		cin >> a;
		vector< vector<int> > uzu(a, vector<int>(a, 0));
		int ulimit, dlimit, rlimit, llimit;
		ulimit = 0;
		dlimit = a-1;
		rlimit = a-1;
		llimit = 2;
		int tate, yoko;
		tate = a-1;
		yoko = 0;
		if (a == 1) {
			uzu[0][0] = 1;
		}
		while (1) {
			if (yoko > rlimit || tate == ulimit) {
				break;
			}
			for (int i = tate; i >= ulimit; i--) {
				uzu[i][yoko] = 1;
			}
			tate = ulimit;
			ulimit += 2;
			if (tate > dlimit || yoko == rlimit) {
				break;
			}
			for (int i = yoko; i <= rlimit; i++) {
				uzu[tate][i] = 1;
			}
			yoko = rlimit;
			rlimit -= 2;
			if (yoko < llimit || tate == dlimit) {
				break;
			}
			for (int i = tate; i <= dlimit; i++) {
				uzu[i][yoko] = 1;
			}
			tate = dlimit;
			dlimit -= 2;
			if (tate < ulimit || yoko == llimit) {
				break;
			}
			for (int i = yoko; i >= llimit; i--) {
				uzu[tate][i] = 1;
			}
			yoko = llimit;
			llimit += 2;
		}
		for (int i = 0; i < a; i++) {
			for (int k = 0; k < a; k++) {
				if (uzu[i][k] == 1) {
					cout << '#';
				} else {
					cout << ' ';
				}
			}
			cout << endl;
		}
	}
	return 0;
}