递归
#include <stdio.h>
#include <stdlib.h>
int N = 4;
int Helix( int x, int y )
{
if ( (x == 1) && (y == 1) )
return(1);
if ( (x - y >= 1) && (x + y <= N) )
return(1 + Helix( x + 1, y ) );
if ( (x - y >= 1) && (x + y > N) )
return(1 + Helix( x, y + 1 ) );
if ( (x - y < 1) && (x + y <= N + 1) )
return(1 + Helix( x, y - 1 ) );
if ( (x - y < 1) && (x + y) > N + 1 )
return(1 + Helix( x - 1, y ) );
else return(0);
}
int main()
{
for ( int i = 1; i <= N; i++ )
{
for ( int j = 1; j <= N; j++ )
printf("%3d",Helix( i, j ));
printf("\n");
}
return 0;
}
非递归