Thursday, September 13, 2018

RECTANGULAR MATRIX

  • Problem Description

    C PROGRAM TO CALCULATE SUM OF UPPER TRIANGULAR ELEMENTS
  • CODING ARENA::
  • #include <stdio.h>
    int main()
    {
      int a[10][10],n,m,i,j,sum=0;
      scanf ("%d",&n);
      scanf ("%d",&m);
      for(i=0;i<n;i++)
        {
        for(j=0;j<n;j++)
          {
          scanf ("%d",&a[i][j]);
          }
        }
      if(n==m)
        {
        for(i=0;i<n;i++)
          {
          for(j=0;j<n;j++)
            {
            if(i<j)
            {
             
            sum=sum+a[i][j];
              
            }
            }
          }
        printf ("%d",sum);
        }
      else
        printf ("entered row and columns is not square matrix");
      
        
        

    return 0;
    }
  • Test Case 1

    Input (stdin)
    3
    
    3
    
    1 2 3
    
    2 1 1
    
    1 2 1
    
    
    Expected Output
    6
  • Test Case 2

    Input (stdin)
    3
    
    4
    
    1 2 3 4
    
    5 6 7 8
    
    9 10 11 12
    
    
    Expected Output
    entered row and columns is not square matrix

No comments:

Post a Comment