URI Online Judge Solution 1534 Array 123 Using C, Python Programming Language.
Read an integer N that is the size of a bidimentional array that must be printed like the given example.
Input
The input contains many test cases and ends with EOF. Each test case consist in a integer number N (3 ≤ N < 70), that indicates the size (lines and columns) of a bidimentional array that must be printed.
Output
For each N read, print the output according to the given example.
Input
The input contains many test cases and ends with EOF. Each test case consist in a integer number N (3 ≤ N < 70), that indicates the size (lines and columns) of a bidimentional array that must be printed.
Output
For each N read, print the output according to the given example.
Solution Using C:
#include <stdio.h>
int main() {
int i,j,n;
while(scanf("%d",&n) != EOF)
{
if(n%2==0)
{
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
if(j==i)
printf("1");
else if(i+j==n+1)
printf("2");
else
printf("3");
}
printf("\n");
}
}
else
{
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
if(i+j==n+1)
printf("2");
else if(j==i)
printf("1");
else
printf("3");
}
printf("\n");
}
}
}
return 0;
}
Comments
Post a Comment