- 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.
15 Antworten
+ 1
https://code.sololearn.com/cDueZ5Tf3rJC/?ref=app
//Please check you can change it to C also by yourself
+ 2
Calvin Thomas good your program is better than of mine
+ 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.*/
+ 1
Dinesh Padhan and Vrushabh Dhanraj Lewade Is there a better way to solve this (with a lesser amount of code)?
+ 1
Calvin Thomas please check my soln
+ 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?
+ 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
+ 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
+ 1
Calvin Thomas sorry your code is working great. I haven't changed all values my bad
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.*/
0
How to solve it.
0
Atul Ah, now I get it. Thanks for posting your code here.
0
I understand.
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("");
}
}
0
Atul Thank you.