Click here to Skip to main content
13,147,956 members (91,300 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
#include <iostream.h>
#include <conio.h>
 
int main(int argc, char *argv[])
{
 

  int a[2],b[2],c[2],i,j,k;
  for(i=0;i<=1;i++)
  {
   cout<<"Enter values of first array ";
   cin>>a[i];
  }
  for(j=0;j<=1;j++)
  {
  cout<<"Enter values of second array ";
  cin>>b[j];
}
for(k=0;k<=1;k++)
{
 
 c[k]=a[i]+b[j];
 cout<<c[k]<<endl;
}
  getche();
 
}




The above program is for adding two arrays store it into third array but this does not give correct answer please help
Posted 6-Dec-12 23:43pm
ALIWAZ407

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Quote:
c[k]=a[i]+b[j];

That is wrong: cahnge to:
c[k]=a[k]+b[k];
  Permalink  
Comments
nv3 7-Dec-12 8:12am
   
That was easy :-)
CPallini 7-Dec-12 8:59am
   
Not so easy. The triple "K" is a bit scaring, after all.
:-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100