Skip to content

Instantly share code, notes, and snippets.

@vigneshsarma
Created September 21, 2011 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vigneshsarma/1231095 to your computer and use it in GitHub Desktop.
Save vigneshsarma/1231095 to your computer and use it in GitHub Desktop.
My first solution with out the base case
#include<stdio.h>
#include<conio.h>
//int w[20][20];
int w[3][3]={1,2,3,4,5,6,7,8,9};
int N=3;
void printer(int n) {
int i,j;
printf("\n ");
for ( i=N-n;i<n;i++) {
printf(" %d",w[N-n][i]);
}
for ( j=N-n+1;j<n;j++) {
printf("\n");
for ( i=N-n;i<n;i++) {
printf(" ");
}
printf("%d",w[j][n-1]);
}
for ( j=N-n+1;j<n;j++) {
printf("\n %d",w[j][N-n]);
}
for ( i=N-n+1;i<n-1;i++) {
printf(" %d",w[n-1][i]);
}
//printer(n-1);
}
int main()
{
int i,j;
/*
printf("enter n:");
scanf("%d",&N);
for ( i=0;i<N;i++) {
for ( j=0;j<N;j++) {
scanf("%d",&w[i][j]);
}
}*/
for ( i=0;i<N;i++) {
printf("\n");
for ( j=0;j<N;j++) {
printf(" %d",w[i][j]);
}
}
printer(N);
return 0;
}
@vigneshsarma
Copy link
Author

Spiraling through a matrix half answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment