Skip to content

Instantly share code, notes, and snippets.

@vigneshsarma
Created September 21, 2011 03:11
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/1231132 to your computer and use it in GitHub Desktop.
Save vigneshsarma/1231132 to your computer and use it in GitHub Desktop.
My Corrected second solution with the base case n<=N/2
#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;
if(n<N/2){
return;
}else{
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment