Write a 'C' Program to calculate sum of elements of upper triangle of a n * n matrix.


#include

void main()
{
    int m[10][10],i,j,n,sum = 0;
    clrscr();
    printf("ENTER NUMBER OF ROWS OR COLOUMNS OF SQUARE MATRIX ::>\n");
    scanf("%d",&n);
    printf("ENTER ELEMENTS OF %d * %d MATRIX ::>\n",n,n);
    for(i = 0 ; i < n ; i++)
    {
        for(j = 0 ; j < n ; j++)
        {
            scanf("%d",&m[i][j]);
        }
    }
    printf("YOU ENTERED MATRIX::>\n");
    for(i = 0 ; i < n ; i++)
    {
        for(j = 0 ; j < n ; j++)
        {
            printf("%d ",m[i][j]);
        }
        printf("\n");
    }

    for(i = 0 ; i < n; i++)
    {
        for(j = 0 ; j < n ; j++)
        {
            if(i < j)
            {
                sum = sum + m[i][j];
            }
        }
    }
    printf("SUM OF ELEMENTS OF UPPER TRINGLE OF MATRIX ::> %d",sum);
    getch();
}
/*OUTPUT::
ENTER NUMBER OF ROWS OR COLOUMNS OF SQUARE MATRIX  ::>
3
ENTER ELEMENTS OF 3 * 3 MATRIX ::>
1 2 3
4 5 6
7 8 9
YOU ENTERED MATRIX::>
1 2 3
4 5 6
7 8 9
SUM OF ELEMENTS OF UPPER TRINGLE OF MATRIX ::> 11
*/
Write a 'C' Program to calculate sum of elements of upper triangle of a n * n matrix. Write a 'C' Program to calculate sum of elements of upper triangle of a n * n matrix. Reviewed by on April 24, 2015 Rating: 5
Powered by Blogger.