Solved programming problem

How To find the sum of lower Triangular matrix in C.

Source code

#include <stdio.h>

int main()

{

    int array[100][100],sum=0;

    int i=0,j=0,r,c;

    printf("Please Enter Row and Column Number: ");

    scanf("%d %d",&r,&c);

    printf("Please Enter 1st %d X %d array: 
",r,c);

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

    {

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

        {

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

        }

    }

    /// add element

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

    {

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

        {

            if(j<i) /// Checking the column number is smaller then row

            {

                sum += array[i][j];

            }

        }

    }

     printf("
Sum of lower triangular matrix: %d
",sum);

    return 0;

}

Output

Please Enter Row and Column Number:3 3

Please Enter 1st 3 X 3 array:

1 0 0

4 5 0

7 8 9

Sum of lower triangular matrix:19

Join the discussion

Add your comment