Addition matrix-java


import java.io.*;
class Additionmat
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter row size");
int n=Integer.parseInt(br.readLine());
System.out.println("enter column size");
int m=Integer.parseInt(br.readLine());
int a[][]=new int[n][m];
int b[][]=new int[n][m];
int c[][]=new int[n][m];
System.out.println("enter elements of a");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println("enter elements of b");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
b[i][j]=Integer.parseInt(br.readLine());
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
System.out.println("resultant matrix is");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println();
}
}
}

No comments:

My Favorite Books

  • C and Data Structures by Ashok N. kamthane
  • Web Technologies by A. A. Puntambekar
  • Learn HTML and CSS with W3Schools
  • Learn JavaScript and Ajax with W3Schools
  • HTML5 Black Book: Covers Css3, Javascript,XML, XHTML, Ajax, PHP And Jquery
  • HTML5 Application Development Fundamentals: MTA Exam 98-375
  • .NET 4.0 Programming 6-In-1, Black Book
  • SQL Server 2008 R2 Black Book
  • Asp.net 4.0 Projects Covers: net 3.5 And .net 4.0 Codes, Black Book
  • UNIX Shell Programming 1 Edition by Yashavant Kanetkar
  • UNIX and Shell Programming 1 Edition by Richard F. Gilberg, Behrouz A. Forouzan
  • Computer Networks by Andrew S. Tanenbaum
  • Multiple Choice questions in computer science by Timothy J Williams