0
Pair of Socks problem in cpp, why output is not coming
#include<iostream> #include<algorithm> using namespace std; int sockspair(int a[],int n) { sort(a,a+n); int count=0; for(int i=0;i<n-1;i+2) { if(a[i]==a[i+1]) { count++; } } return count; } int main() { int n; cin>>n; int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; } int result=sockspair(a,n); cout<<"Pairs of socks are"<<result; }
2 Respostas
+ 5
Try to use i += 2 instead of i+2
0
Thanks bro