Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C programming question I can not figure out. Please help me out: (Duplicate Elim

ID: 3681429 • Letter: C

Question

C programming question I can not figure out. Please help me out:

(Duplicate Elimination) Use a single-subscripted array to solve the following problem.
Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print
it only if it’s not a duplicate of a number already read. Provide for the “worst case” in which all 20
numbers are different. Use the smallest possible array to solve this problem.

My code:

#include
#include

#define SIZE 20

int
main (void)
{
setbuf (stdout, NULL);
size_t i;
int numberList[SIZE] =
{ 0 };
int numbers = 0;
int count = 0;
int duplicate = 0;
int duplicateFlag = 0;

for (i = 1; i <= SIZE; i++)
{
printf ("%i. Enter a number between 10 and 100, inclusive: ", i);
scanf ("%d", &numbers);

duplicateFlag = 0;

while (numbers >= 100 || numbers <= 10)
   {

   printf ("Invalid number ");
   printf ("%i. Enter a number between 10 and 100, inclusive: ", i);
   scanf ("%d", &numbers);
   }

for (duplicate = 0; duplicate < i; duplicate++)
   {
   if (numbers == numberList[duplicate])
   {
   duplicateFlag = 1;
   break;
   }

   }
if (duplicateFlag == 0)
   {
   numberList[i] = numbers;
   }

}
puts (" The non duplicate values are: ");
for (i = 0; i < count; i++)
{
printf ("%d ", numberList[i]);
}
printf (" ");
return 0;
}

Explanation / Answer

code in C++