Sum of Array Program in Cpp 2022 - mymixindia.com

Sum of Array Program in Cpp 2022


Sum of Array Program in Cpp 2022

//.......Mymixindia.com.........
//.....Sum of Arrays program...
#include <iostream>
using namespace std;
 int main () {
     //.....add 2d arrays...

int a[10][10], b[10][10],c[10][10],i,j; //....initilizing the array varibles a,b and iteration variables i and j......

cout<<"Sum of 2 Matrices \n";

cout<<"Enter the values of the matrix one \n";
//.....user input for array a...
for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cin>>a[i][j];
  }
}
cout<<"Now Enter the value of matrix b"<<endl;
//......user input for array b....
for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cin>>b[i][j];
  }
}

cout<<"Sum Start....."<<endl;
//......adding the array and storing them inside c...///
for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    c[i][j] = a[i][j] + b[i][j];
  }
}

cout<<"Sum Finish....... \n";
cout<<"Array A \n"; //......printing the values of array a.....
for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"i = "<<i<<" j = "<<j<<" a[i][j] = "<<a[i][j]<<endl;
  }
}

cout<<"-------------------------------------------------------\n";

cout<<"Array B \n"; //......printing the values of array b.....
for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"i = "<<i<<" j = "<<j<<" b[i][j] = "<<b[i][j]<<endl;
  }
}

cout<<"-------------------------------------------------------\n";
cout<<"Resultant array \n"; //......printing the values of array c (resultant array).....
for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
  {
    cout<<"i = "<<i<<" j = "<<j<<" c[i][j] = "<<c[i][j]<<endl;
  }
}

cout<<"-------------------------------------------------------\n";



return 0; 
}

 

The output of the above program

Sum of 2 Matrices 
Enter the values of the matrix one 
23
34
456
67
8
9
9
12
23
Now Enter the value of matrix b
27
23
34
456
77
54
3
12 
112
Sum Start.....
Sum Finish.......       
Array A 
i = 0 j = 0 a[i][j] = 23
i = 0 j = 1 a[i][j] = 34
i = 0 j = 2 a[i][j] = 456
i = 1 j = 0 a[i][j] = 67
i = 1 j = 1 a[i][j] = 8
i = 1 j = 2 a[i][j] = 9
i = 2 j = 0 a[i][j] = 9
i = 2 j = 1 a[i][j] = 12
i = 2 j = 2 a[i][j] = 23
-------------------------------------------------------
Array B
i = 0 j = 0 b[i][j] = 27
i = 0 j = 1 b[i][j] = 23
i = 0 j = 2 b[i][j] = 34
i = 1 j = 0 b[i][j] = 456
i = 1 j = 1 b[i][j] = 77
i = 1 j = 2 b[i][j] = 54
i = 2 j = 0 b[i][j] = 3
i = 2 j = 1 b[i][j] = 12
i = 2 j = 2 b[i][j] = 112
-------------------------------------------------------
Resultant array
i = 0 j = 0 c[i][j] = 50
i = 0 j = 1 c[i][j] = 57
i = 0 j = 2 c[i][j] = 490
i = 1 j = 0 c[i][j] = 523
i = 1 j = 1 c[i][j] = 85
i = 1 j = 2 c[i][j] = 63
i = 2 j = 0 c[i][j] = 12
i = 2 j = 1 c[i][j] = 24
i = 2 j = 2 c[i][j] = 135
-------------------------------------------------------

 

Related Posts:

Pointer Program with Aaary and Function in Cpp 2022

Pointer Program in Cpp 2022

Program to Print Prime Number in CPP 2020

5 Namespace Program in C++ 2022

Constructors Program in Java

Java Data Type Program

HTML Tutorials 

CSS tutorials