Array targer sum pair problem..Can anyone tell me whats wrong in this code

#include<bits/stdc++.h>
using namespace std;
void sumArray(int n,int m,int *a)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n&&j!=i;j++)
{
if((a[i]+a[j])==m)
{
cout<<a[i]<<" and "<<a[j]<<endl;
}
else
{
break;
}
}
}
}
int main()
{
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sumArray(n,m,a);
return 0;

}

Hi,Aniket
Your code is partially correct But your code will print a pair two time eg. (2,4) and (4,2) also it is more time consuming,try to optimize it using binary search and a pointer