C Program
#include<stdio.h>
int main(){
int p,q,i,j;
scanf("%d %d",&p,&q);
char mat[1000][1000];
int top=0,bottom=p-1,left=0,right=q-1;
char ch='Y';
while(top<=bottom && right>=left){
for(i=left;i<=right;i++)
mat[top][i]=ch;
for(i=top+1;i<=bottom;i++)
mat[i][right]=ch;
if(top<bottom)
for(i=right-1;i>=left;i--)
mat[bottom][i]=ch;
if(left<right)
for(i=bottom-1;i>top;i--)
mat[i][left]=ch;
top++;bottom--;left++;right--;
if(ch=='Y') ch='0';
else ch='Y';
}
for(i=0;i<p;i++){
printf("%c",mat[i][0]);
for(j=1;j<q;j++)
printf(" %c",mat[i][j]);
printf("\n");
}
return 0;
}
0 Comments