i am trying to find a pair which sums a given number. after i get all the outputs i get a '9' as output at the end. can someone please tell me what's the problem ? here is my code :
include
using namespace std;
//searching pair sums up x
int pairr(int a[],int x,int size)
{
for(int i=0;i<size;i++)
for(int j=1;j<size;j++)
if(a[i]+a[j]==x) cout<<a[i]<<"+"<<a[j]<<" "<<endl;
}
int main()
{
int a[] = {12,32,34,45,65,56,65,67,78};
int size = sizeof(a)/sizeof(a[0]);
int x=112;
cout<<pairr(a,x,size)<<endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire