Answers for "Sum of upper & lower triangles elements"

C
0

Sum of upper & lower triangles elements

#include <stdio.h>

int main()
{

    int a[3][3],i,j,upper_sum=0,lower_sum=0;
    printf("Enter elements for the matrix : \n");
    for(i = 0; i < 3; i++){
        for(j = 0; j < 3; j++){
            printf("Matrix[%d][%d]: \n",i,j);
            scanf("%d",&a[i][j]);
        }
    }

    printf("The Matrix: \n");
    for(i = 0; i < 3; i++){
        for(j = 0; j < 3; j++){
            
            printf("%d ",a[i][j]);
        }
        printf("\n");
    }

    printf("Getting sum... \n");
    for(i = 0; i < 3; i++){
        for(j = 0; j < 3; j++){
            if(i < j){
                printf("The Upper Triangle elements are %d\n",a[i][j]);
                upper_sum+=a[i][j];
            }
            if(i > j){
                printf("The lower Triangle elements are %d\n",a[i][j]);
                lower_sum+=a[i][j];
            }
            
            
        }
       
    }
    
    printf("Sum of Uppper triangles are : %d\n",upper_sum);
    printf("Sum of lower triangles are : %d\n",lower_sum);



    return 0;
}
Posted by: Guest on July-19-2021

Code answers related to "C"

Browse Popular Code Answers by Language