You are on page 1of 2

2D ARRAYS ASSIGNMENT

Name: MEGHANA R
Reg no: 20BEC1042

1. Write a C Program to display the following pattern:


 0     1   1   1   1  1
-1    0    1   1   1  1
-1  -1    0   1   1  1
-1  -1  -1   0   1   1
-1  -1  -1  -1   0  1
-1 -1   -1  -1  -1  0
Code:
#include <stdio.h>
void main()
{
int A[6][6];
int i,j;
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
if(i==j)
A[i][j]=0;
else if(i<j)
A[i][j]=1;
else
A[i][j]=-1;
}
}
for(i=0;i<6;i++)
{
for(j=0;j<6;j++)
{
printf("%d ",A[i][j]);
}
printf("\n");
}
}

You might also like