Sunday, 3 June 2012

C++ Program to Adding elements of two given arrays into the third array

C++ Program to Adding elements of two given arrays into the third array



 # include<iostream.h>
# include <conio.h>
void main()
{
clrscr();
int a[10],b[10],c[10],s,i;
cout<<"enter the 10 numbers";
for(i=0;i<10;i++)
{
cin>>a[i];
}
// creating second array
cout<<"enter the 10 numbers";
for (i=0;i<10;i++)
{
cin>>b[i];
}
//adding the sum of two arrays into a new array
for(i=0;i<10;i++)
{
s = a[i] + b[i];
c[i] = s;
}
//printing of an array
cout<<endl;
cout<<"Printing array A"<<endl;
for (i=0;i<10;i++)
{
cout<<a[i]<<" ";
}
cout<<endl;
cout<<"Printing array B"<<endl;
for ( i= 0;i<10;i++ )
{
cout<<b[i]<<" ";
}
cout<<endl;
cout<<"Printing array C"<<endl;
for (i=0;i<10;i++)
{
cout<<c[i]<<" ";
}
getch();
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More