You are given two int variables j and k, an int array zipcodeList that has been declared and initialized, an int variable nZips that contains the number of elements in zipcodeList, and a bool variable duplicates. Write some code that assigns true to duplicates if any two elements in the array have the same value, and that assigns false to duplicates otherwise. Use only j, k, zipcodeList, nZips, and duplicates.
.
.
Click on the title for the solution
.
.
duplicates=false;
for (k=0; k<nZips; k++)
for (j=0; j<k; j++)
{
if ( zipcodeList[j]==zipcodeList[k])
{
duplicates=true;
break;
}
}
.
Click on the title for the solution
.
.
This is the answer:
:
duplicates=false;
for (k=0; k<nZips; k++)
for (j=0; j<k; j++)
{
if ( zipcodeList[j]==zipcodeList[k])
{
duplicates=true;
break;
}
}
Comments
Post a Comment