u

Wednesday, 6 June 2012

C++ Program to create two arrays of 3x4 and compute their sum in a new array

C++ Program to create two arrays of 3x4 and compute their sum in a new array. Display the new array so obtained.

#include<iostream.h>
#include<conio.h>
main()
{
int a[3][4],b[3][4],c[3][4],i,j;
// creation of the array
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
    cout<<"enter a number for the array a and b ";
    cin>>a[i][j]>>b[i][j];

    }
 }
 // print the array a
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
  cout<<a[i][j]<<" ";
  }
cout<<"\n";
}
//print array b
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
  cout<<b[i][j]<<" ";
  }
cout<<"\n";
}
 // get the sum in a new array
for(i=0;i<3;i++)
{
  for(j=0;j<4;j++)
  {
  c[i][j]=a[i][j]+b[i][j];
  }
}
// display array c
cout<<"The array c is "<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
cout<<c[i][j]<<" ";
}
cout<<endl;
}
getch();
return 0;
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More