0% found this document useful (0 votes)
3 views

2 D ARRAY

computer python 2d array chapter

Uploaded by

pauloindrisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

2 D ARRAY

computer python 2d array chapter

Uploaded by

pauloindrisha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

2D ARRAY

// WRITE A PROGRAM TO ADD TWO MATRICES.

#include<stdio.h>

#include<conio.h>

int main()

int a[3][3],b[3][3],c[3][3],i,j;

printf("Enter A matrix\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

scanf("%d",&a[i][j]);

printf("Enter B matrix\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

scanf("%d",&b[i][j]);

}
}

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

c[i][j]=a[i][j]+b[i][j];

}}

printf("RESULT\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

printf("%d\t",c[i][j]);

printf("\n");

return 0;

// WRITE A PROGRAM TO ADD DIOGONAL ELEMENTS OF A MATRIX

#include<stdio.h>

#include<conio.h>

int main()
{

int a[3][3],i,j,sum=0;

printf("Enter A matrix\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

scanf("%d",&a[i][j]);

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

if(i==j)

sum=sum+a[i][j];

printf("sum=%d\n",sum);

return 0;
}

WRITE A PROGRAM TO INPUT A MATRIX AND PRINT IT TRANSPOSE

#include<stdio.h>

#include<conio.h>

int main()

int a[3][3],i,j,a1[3][3];

printf("Enter A matrix\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

scanf("%d",&a[i][j]);

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

a1[i][j]=a[j][i];

}
printf("original matrix\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

printf("%d\t",a[i][j]);

printf("\n");

printf("Transpose matrix\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

printf("%d\t",a1[i][j]);

printf("\n");

return 0;

You might also like