Q : Write a ‘C’ Program to find Sum of lower triangular elements in a matrix.
Answer :
Lower triangular
Lower triangular matrix is a special square matrix whole all elements above the main diagonal is zero.
Program :
#include<stdio.h>
#include<conio.h>
#define MAXR 3
#define MAXC 3
/*============================
Girfa Student Help
sum of lower triangular matrix
==============================*/
void main()
{
int A[MAXR][MAXC];
int row, col, sum = 0;
printf("Enter
elements in matrix of size %dx%d: \n",
MAX_ROWS, MAX_COLS);
for (row = 0; row<MAXR; row++)
{
for (col = 0; col<MAXC; col++)
{
scanf("%d",
&A[row][col]);
}
}
/* Find
sum of lower triangular matrix */
for (row = 0; row<MAXR; row++)
{
for (col = 0; col<MAXC; col++)
{
if (col<row)
{
sum += A[row][col];
}
}
}
printf("Sum
of lower triangular matrix = %d", sum);
}
No comments:
Post a Comment