#include<stdio.h>
int main()
{
int n,m,i,j,a[100][100],b[100][100];
printf("Enter row and col:");
scanf("%d%d",&n,&m);
printf("Matrix A :
");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("a[%d][%d] : ",i,j);
scanf("%d",&a[i][j]);
}
}
printf("Matrix B :
");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("b[%d][%d] : ",i,j);
scanf("%d",&b[i][j]);
}
}
printf("Sum of matrix :
");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d ",(a[i][j]+b[i][j]));
}
printf("
");
}
}
import java.util.Scanner;
public class MatrixAddition {
private static Scanner scanner = new Scanner(System.in);
private double [][] arr;
private int columns ;
private int raws ;
private static int numberOfMat = 1;
public void setRawAndColumns(int raws, int columns){
System.out.println("(Enter number of raws.)
");
raws = scanner.nextInt();
System.out.println("(Enter number of columns).
");
columns = scanner.nextInt();
SetMatrix(raws,columns);
}
private void SetMatrix(int r , int c){
this.raws = r;
this.columns = c;
this.arr = new double[raws][columns];
enterValues(this.raws,this.columns,this.arr);
double [][] nextMat = new double[this.raws][this.columns];
enterValues(this.raws,this.columns, nextMat);
calculateMatrix(this.arr,nextMat);
}
private double[][] enterValues(int r , int c, double[][]arr){
System.out.println("Enter Values for matrix #"+(this.numberOfMat));
++this.numberOfMat;
for(int i = 0 ; i < arr.length ; ++i ){
for(int j = 0; j < arr[0].length ; ++j ){
System.out.println("raw #"+(i+1)+" Column #"+(j+1));
arr[i][j]= scanner.nextDouble();
}
}
return arr;
}
private double[][] calculateMatrix(double[][] mat,double nextMat[][]){
double [] [] sum = new double[this.raws][this.columns];
for(int i = 0 ; i < mat.length ; ++i){
for(int j = 0 ; j < mat[0].length ; ++j){
sum[i][j]+= (mat[i][j]+nextMat[i][j]);
}
}
printmatrix(sum);
return null;
}
private void printmatrix(double [][] sum){
for(int i = 0 ; i < sum.length; ++i){
System.out.print("[ ");
for (int j = 0 ; j < sum[0].length ; ++j){
System.out.print(sum[i][j]+" ");
}
System.out.println("]");
}
}
}
Code Example |
---|
C :: delay in c programming for windows |
C :: convert string to int c |
C :: rust cross compile |
C :: declare string in c |
C :: mongodb read |
C :: c median of an array |
C :: function component with props |
C :: #0000ff |
C :: imprimir matriz |
C :: unpack and repack deb package |
C :: esp8266 wifi.config does not work |
C :: looping through an array in c |
C :: stddef.h |
C :: string in c and how it works |
C :: how to open form in vb.net |
C :: %= in c |
C :: what is the last character of a string in c |
C :: C Syntax of struct |
C :: C Pass Individual Array Elements |
C :: 4 byte alignment c code |
C :: how to change the smartart style to 3D polished in powerpoint |
C :: leer string en c |
C :: Battlefield4u.com |
C :: how to stop aws alb temporarily |
C :: command line arguments to copy paste in c |
C :: Entering raw mode |
C :: c byte vs char |
C :: find a substring within a string in c and return the index |
C :: Laravel installation on Linux |
C :: or gmode inline image |