Solved programming problem

How To find the sum of Upper 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 row number is smaller then column

            {

                sum += array[i][j];

            }

        }

    }

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

    return 0;

}

Output

Please Enter Row and Column Number: 3 3


Please Enter 1st 3 X 3 array:


1 2 3
0 5 6
0 1 2


Sum of Upper triangular matrix:11

Join the discussion

Add your comment