151k views
0 votes
You are given a variable zipcode_list that refers to a list. write some code that assigns true to a variable duplicates if there are two adjacent elements in the list that have the same value, but that otherwise assigns false to duplicates otherwise. in order to accomplish this, you may, if you wish, use one other variable, k. use only k, zipcode_list, and duplicates.

User Mateu
by
8.0k points

1 Answer

2 votes
Some code that assigns true to a variable duplicates if there are two adjacent elements in the list that have the same value, but that otherwise assigns false to duplicates otherwise is: duplicates=false; for (k=0; k<nZips-1; k++){ if (zipcodeList[k]==zipcodeList[k+1]){ duplicates=true; break; } }
User Teja Kumar Bethina
by
9.2k points