Thursday, 21 January 2021

Write a Program in C++ to add 2 matrices.

 //WAP TO ADD 2 MATRICES

#include<iostream>

using namespace std;

main()

{

  int i,j,n;

  cout<<"Enter the Size of the Matrix"<<endl;

  cin>>n;

  int a[n][n],b[n][n],c[n][n];

  cout<<"Enter the elements of the Matrix a"<<endl;

  for(i=0;i<n;i++)

  {

  for(j=0;j<n;j++)

  cin>>a[i][j];

  }

  cout<<"Enter the elements of the Matrix b"<<endl;

  for(i=0;i<n;i++)

  {

  for(j=0;j<n;j++)

  cin>>b[i][j];

  }

  for(i=0;i<n;i++)

  {

  for(j=0;j<n;j++)

  c[i][j]=a[i][j]+b[i][j];

  }

  cout<<"The Sum of the Two Matrices:"<<endl;

  for(i=0;i<n;i++)

  {

  for(j=0;j<n;j++)

  cout<<c[i][j]<<" ";

  cout<<endl;

  }

}

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...