2 D Programs
2 D Programs
2 D Programs
#include <stdio.h>
int main()
{
int r,c,i,j,pdiag_sum = 0;
int matrix[r][c];
}
}
printf("The Sum of primary diagonal elements is : %d\n", pdiag_sum);
return 0;
}
// sum of secondary diagonal elements
#include <stdio.h>
int main()
{
int r,c,i,j,Sdiag_sum = 0;
int matrix[r][c];
Sdiag_sum = 0;
return 0;
}
//symmetric or not
#include <stdio.h>
int main()
{
int n, m, symmetric = 1;
return 0;
}
// Addition of two matrix
#include<stdio.h>
int main()
{
int i,j,row1,col1,row2,col2;
else
{
printf("Enter %d elements for A \n",row1*col1);
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=0;i<row1;i++)
{
for(j=0;j<col1;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("The Elements of Matrix B is\n");
for(i=0;i<row2;i++)
{
for(j=0;j<col2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
for(i=0;i<row1;i++)
{
for(j=0;j<row2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
}
}
return 0;
}
// write c program to find the multiplication of two matrix
#include <stdio.h>
int main()
{
if (col1 != row2)
{
printf("Error:Multipilication is not possible\n");
}
else
{
printf("Enter %d elements of A matrix: \n",row1*col1);
for (i = 0; i < row1; i++)
{
for (j = 0; j < col1; j++)
{
scanf("%d", &A[i][j]);
}
}
scanf("%d", &B[i][j]);
}
}
// Matrix multiplication
for (i = 0; i < row1; i++)
{
for (j = 0; j < col2; j++)
{
C[i][j]=0;
for (k = 0; k < col1; k++)
{
C[i][j] = C[i][j] + A[i][k] * B[k][j];
}
}
}