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,b,c,d,e,f,g,h; for(a=0; a<z; a++) { for(b=0; b<z; b++) ara[a][b]=3; } for(a=0; a<z; a++) ara[a][a]=1; d=z-1; for(a=0,b=d; a<z;a++,b--) ara[a][b]=2; for(a=0; a<z; a++) { for(b=0; b<z; b++) printf("%d",ara[a][b]); printf("\n"); } } return 0; }
Jesus christ men, I'd really like to know why you create so much variables, I only needed 2 (one of them being the array) to get the job done. Could you explain why you choose to do it this way? here's my code:
ReplyDelete#include
#include
using namespace std;
int main(){
int m[70][70]={},n;
while (scanf("%d",&n)!=EOF){
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
if (i==j) m[i][j]=1;
else m[i][j]=3;
if (i+j==n-1) m[i][j]=2;
printf("%d",m[i][j]);
if (j==n-1) cout << endl;
}
}
}
return 0;
}
Easier and clear solution:
ReplyDeletehttps://pastebin.com/Tap9YKiS