| endosymbiosis |
#include<stdio.h>
int main(void)
{
int input, array[15][15]={0}, i=0, j=0, top=0, bottom=0, count=1, direct=1;
printf("Input your number (1-15):");
scanf("%d", &input);
bottom=input;
while(array[i][j]==0){
if(direct){
if(i<bottom-1)
array[i++][j]=count++;
else if(j<bottom)
array[i][j++]=count++;
if(j==bottom){
i--;
j--;
bottom--;
direct=0;
}
}
else{
if(i>top)
array[i--][j]=count++;
else if(j>top)
array[i][j--]=count++;
if(j==top){
j++;
i++;
top++;
direct=1;
}
}
};
for(i=0;i<input;i++){
for(j=0;j<input;j++){
printf("%4d", array[i][j]);
}
printf("\n");
}
printf("\n");
return 0;
} |
2011/06/04 |
|