0% found this document useful (0 votes)
13 views24 pages

2D Array

Uploaded by

hanvai143
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)
13 views24 pages

2D Array

Uploaded by

hanvai143
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/ 24

#include <stdio.

h>
main()
{
int A[20][20], m,n, i,j;
printf("\nEnter the number of rows and columns: ");
scanf("%d%d",&m,&n);
for(i=0;i<m; i++)
{
for(j=0;j<n;j++)
{
printf("\nEnter element for %d row and %d column : ", i,j);
scanf("%d", &A[i][j]);
}
}
printf("\n The elements enetered are");
printf("\n*******************\n");
for(i=0;i<m; i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("%d\t", A[i][j]);
}
}
2. Sum of row elements : Program #include <stdio.h>
int main()
{
int A[20][20], m,n, i,j, sum;
printf("\nEnter the number of rows and columns: ");
scanf("%d%d",&m,&n);
for(i=0;i<m; i++)
{
for(j=0;j<n;j++)
{
printf("\nEnter element for %d row and %d column : ", i,j);
scanf("%d", &A[i][j]);
}
}
for(i=0;i<m; i++)
{
sum =0;
for(j=0;j<n;j++)
{
sum+=A[i][j];
}
printf("\n sum of %d row is %d\t", (i+1), sum);
}
}
if(m==n)
{
for(i=0;i<m; i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
sum_main+=A[i][j];
}
}
}
for(i=0;i<m; i++)
{
for(j=0;j<n;j++)
{
if((i+j)==(m-1))
{
sum_alternate+=A[i][j];
}
}
} }
printf("\n The sum of main diagonal is : %d", sum_main);
printf("\n The sum of alternate diagonal is : %d", sum_alternate);
if(m==n)
{
for(i=0;i<m; i++)
{
for(j=0;j<n;j++)
{
if(i<j)
{
sum_upper+=A[i][j];
}
else if(i>j)
{
sum_lower+=A[i][j];
}
}
}
}
else
{ printf("\n Enter same number of rows and columns");}

printf("\n The sum of upper triangle element is : %d", sum_upper);


printf("\n The sum of lower triangle element is : %d", sum_lower);
for (int j= 0; j < N; j++)
C[i][j]=A [i][j]+B [i][j];
for(i=0;i<m; i++)
{
for(j=0;j<n;j++)
{
B[j][i]=A[i][j];
}

}
for(i=0;i<n; i++)
{
printf("\n");
for(j=0;j<m;j++)
{
printf("%d\t",B[i][j]);
}
}
#include <stdio.h>
void main()
{
int a[25][25],b[25][25],c[25][25],i,j,k,r,s, m,n;
printf("Enter the no of rows and columns of the first matrix\n");
scanf("%d%d",&m,&n);
printf("Enter the no of rows and columns of the second matrix\n");
scanf("%d%d",&r,&s);
if(n!=r)
printf("\n The matrix cannot multiplied");
else
{
printf("\n Enter the elements of first matrix ");
for(i= 0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("\t%d",&a[i][j]);
}
printf("\n Enter the elements of second matrix ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("\t%d",&b[i][j]);
}
printf("\n The element of first matrix is");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",a[i][j]);
}
printf("\n The element of second matrix is");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",b[i][j]);
}
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
c[i][j]=0;
for(k=0;k<m;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\n Multiplication of two matrix is");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",c[i][j]);
}
}

You might also like