The following code is twice as fast using 'max' rather than just 11 in the three loops. Could someone explain why this is so?
thanks in advance
Code:
int main() { int const max=11; int count=0,num=0; int a[]={2,3,5,7,6,1,4,9,8,2,5}; //print array cout<<"\n\n"; cout<<"the array is: \n"; for(int i=0;i<max;i++) cout<<a[i]<<" "; //now find which integers are repeated for(int i=0;i<max;i++) { for(int j=0;j<max;j++) { if(a[j]==i) count++; } if(count<1)continue; if(count>num)num=count; cout<<"\nthere was "<<count<<" "<<i; count=0; } cout<<"\nthe most repeats was "<<num<<endl; }
Comment