Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import java.util.*;
  2. class LowerTriangle
  3. {
  4. static int add(int a[][],int r,int c)
  5. {
  6. int i,j,totalsum=0;
  7. for(i=0;i<r;i++)
  8. {
  9. for(j=0;j<c;j++)
  10. {
  11. if(j<i)
  12. {
  13. totalsum=totalsum+a[i][j];
  14. }
  15. }
  16. }
  17. return totalsum;
  18.  
  19. }
  20.  
  21. public static void main(String args[])
  22. {
  23. Scanner s=new Scanner(System.in);
  24. int r,c,lower_sum=0;
  25. System.out.println("Enter No of Rows and Columns");
  26. r=s.nextInt();
  27. c=s.nextInt();
  28. int a[][]=new int[100][100];
  29. for(int i=0;i<r;i++)
  30. {
  31. for(int j=0;j<c;j++)
  32. {
  33. a[i][j]=s.nextInt();
  34. }
  35. }
  36. lower_sum=add(a,r,c);
  37. System.out.println("Sum of Lower Triangle Matrix is:"+lower_sum);
  38. }
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement