Program to Find the Sum of Each Row and Each Column of Matrix

Program to Find the Sum of Each Row and Each Column of Matrix 2021

Find the Sum of Each Row and Each Column of Matrix 2021 | Sum of Rows and Columns in 2d Array in Java | Find Sum of Each Row and Column.
 Here is  the Program to Find the Sum of Each Row and Each Column of Matrix 2021.

We are uploading these types of program. However, if you need fully compiled solution of any type of Java program then simply leave a comment below, we will help you at the earliest. 😊😊

 import java.util.*;  
 public class Sum_of_Rows_And_Columns  
 {  
   public static void main()  
   {  
     int s=0;  
     int d=0;  
     Scanner sc=new Scanner(System.in);  
     System.out.println("Enter the number of Rows");  
     int r=sc.nextInt();  
     System.out.println("Enter the number of Columns");  
     int c=sc.nextInt();  
     int arr[][]=new int[r][c];  
     System.out.println("Enter the elements of Matrix");  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         arr[i][j]=sc.nextInt();  
       }  
     }  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         System.out.print(arr[i][j]+" ");   
       }  
       System.out.println("");  
     }  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         s=s+arr[i][j];  
       }  
       System.out.println("Sum Of Row "+i+"= "+s);  
       s=0;  
     }  
     for(int i=0;i<r;i++)  
     {  
       for(int j=0;j<c;j++)  
       {  
         d=d+arr[j][i];  
       }  
       System.out.println("Sum Of Column "+i+"= "+d);  
       d=0;  
     }  
   }  
 }   
 ------------  
 OUTPUT:-  
 ------------  
 Enter the number of Rows  
 4  
 Enter the number of Columns  
 4  
 Enter the elements of Matrix  
 1  
 5  
 9  
 8  
 7  
 4  
 5  
 6  
 3  
 2  
 1  
 4  
 5  
 2  
 3  
 6  
 1 5 9 8   
 7 4 5 6   
 3 2 1 4   
 5 2 3 6   
 Sum Of Row 0= 23  
 Sum Of Row 1= 22  
 Sum Of Row 2= 10  
 Sum Of Row 3= 16  
 Sum Of Column 0= 16  
 Sum Of Column 1= 13  
 Sum Of Column 2= 18  
 Sum Of Column 3= 24   
 ------------------- 

Checkout:-  Print Two Dimensional/Multidimensional Array Java

Checkout:- Java Program to Add Two Matrices

Post a Comment

0 Comments