- 2

#include <stdio.h> // Now define main function int main() { int i,j; for(i=1;i<=9;i++) { for(j=1;j<=9;j++) {

How to solve the code for step by step process.

15th May 2021, 6:24 PM
Vrushabh
Vrushabh - avatar
15 odpowiedzi
+ 1
https://code.sololearn.com/cDueZ5Tf3rJC/?ref=app //Please check you can change it to C also by yourself
5th Jun 2021, 12:26 PM
Atul [Inactive]
+ 2
Calvin Thomas good your program is better than of mine
8th Jun 2021, 9:43 AM
Atul [Inactive]
+ 1
#include <stdio.h> // Now define main function int main() { int i,j; for(i=1;i<=9;i++) { for(j=1;j<=9;j++) { if(i==1||i==9||j==1||j==9) printf("5"); else if(i==2||i==8||j==2||j==8) printf("4"); else if(i==3||i==7||j==3||j==7) printf("3"); else if(i==4||i==6||j==4||j==6) printf("2"); else if(i==5||i==5||j==5||j==5) printf("1"); } printf("\n"); } return 0; } /* 555555555 544444445 543333345 543222345 543212345 543222345 543333345 544444445 555555555 Process finished.*/
16th May 2021, 4:04 AM
Dinesh Padhan
+ 1
Dinesh Padhan and Vrushabh Dhanraj Lewade Is there a better way to solve this (with a lesser amount of code)?
16th May 2021, 5:48 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Calvin Thomas please check my soln
5th Jun 2021, 12:41 PM
Atul [Inactive]
+ 1
Calvin Thomas my pleasure. Vrushabh Dhanraj Lewade please tell if you have understood or not? Or shall u need me to embed comments to it?
5th Jun 2021, 6:29 PM
Atul [Inactive]
+ 1
Calvin Thomas actually at first it strike to me the if else soln but then I thought the logic and framed it. My code is not upto th mark but still working. In case if you plz optimise it
5th Jun 2021, 6:42 PM
Atul [Inactive]
+ 1
Calvin Thomas just check if it is going for all numbers or not. Because I found that the pattern's base is shifting right on entering 6. I may be wrong
7th Jun 2021, 9:09 AM
Atul [Inactive]
+ 1
Calvin Thomas sorry your code is working great. I haven't changed all values my bad
8th Jun 2021, 9:42 AM
Atul [Inactive]
0
#include <stdio.h> // Now define main function int main() { int i,j; for(i=1;i<=9;i++) { for(j=1;j<=9;j++) { if(i==1||i==9||j==1||j==9) printf("5"); else if(i==2||i==8||j==2||j==8) printf("4"); else if(i==3||i==7||j==3||j==7) printf("3"); else if(i==4||i==6||j==4||j==6) printf("2"); else if(i==5||i==5||j==5||j==5) printf("1"); } printf("\n"); } return 0; } /* 555555555 544444445 543333345 543222345 543212345 543222345 543333345 544444445 555555555 Process finished.*/
15th May 2021, 6:24 PM
Vrushabh
Vrushabh - avatar
0
How to solve it.
15th May 2021, 6:25 PM
Vrushabh
Vrushabh - avatar
0
Atul Ah, now I get it. Thanks for posting your code here.
5th Jun 2021, 4:12 PM
Calvin Thomas
Calvin Thomas - avatar
0
I understand.
5th Jun 2021, 7:13 PM
Vrushabh
Vrushabh - avatar
0
Atul Here's something that I've managed to make: #include <stdio.h> int main() { for (int n=1,i,k;n<10;n++) { i = (n>5)?10-n:n; for (int j=1;j<10;j++) { k = (j>5)?10-j:j; printf("%d ",6-(k>i?i:k)); } puts(""); } }
7th Jun 2021, 6:59 AM
Calvin Thomas
Calvin Thomas - avatar
0
Atul Thank you.
8th Jun 2021, 11:30 AM
Calvin Thomas
Calvin Thomas - avatar