Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/
#include <stdio.h>
int main()
{
/*freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);*/
int z;
while(scanf("%d",&z)!=EOF)
{
int ara[z][z];
int a,aa,b,c,d,e,f,g,x,y;
for(a=0; a<z; a++)
{
for(b=0; b<z; b++)
ara[a][b]=0;
}
for(a=0; a<z; a++)
ara[a][a]=2;
d=z-1;
for(a=0,b=d; a<z;a++,b--)
ara[a][b]=3;
c=z/3;
e=z-c-c;
for(f=c,x=1; x<=e; f++,x++)
{
for(g=c,y=1; y<=e; g++,y++)
ara[f][g]=1;
}
if(z%2==1)
aa=z/2;
else
aa=(z/2)-1;
ara[aa][aa]=4;
for(a=0; a<z; a++)
{
for(b=0; b<z; b++)
printf("%d",ara[a][b]);
printf("\n");
}
printf("\n");
}
return 0;
}
do you know why this code don´t pass?
ReplyDeleteint n, j, i, o, tj, ti;
while(scanf("%i", &n)!=EOF){
for(i=0;i<n;i++){
for(j=0;j<n;j++){
o = n-1;
ti = o-i;
tj = o-j;
if(i<o/3 || j<o/3 || ti<o/3 || tj<o/3){
if(i==j){
printf("2");
}
else if(i+j==n-1){
printf("3");
}
else{
printf("0");
}
}
else{
if(i==o/2 && j==o/2){
printf("4");
}
else{
printf("1");
}
}
}
printf("\n");
}
printf("\n");
}
for(f=c,x=1; x<=e; f++,x++)
ReplyDeletefor(g=c,y=1; y<=e; g++,y++)
why you use x and y