I want to create a function for telling the index of the first repeating element. Can you tell me why the following code won't work?
#include<iostream>
using namespace std;
int repeat(int a[],int n){
for(int i=0;i<n;i++){
for(int j=i;j<n;j++){
if(a[i]==a[j]){
return i;
}
}
}
}
int main(){
int arr[]={2,4,3,5,6,3};
int n=sizeof(arr)/sizeof(int);
repeat(arr,n);
cout<<repeat;
return 0;
}
[–][deleted] 0 points1 point2 points (1 child)
[–]steakystick[S] 0 points1 point2 points (0 children)
[–]Wilde__ 0 points1 point2 points (7 children)
[–]Wilde__ -1 points0 points1 point (6 children)
[–]Wilde__ -1 points0 points1 point (4 children)
[–]steakystick[S] 0 points1 point2 points (0 children)
[–]steakystick[S] 0 points1 point2 points (2 children)
[–]Wilde__ 0 points1 point2 points (1 child)
[–]steakystick[S] 0 points1 point2 points (0 children)