Question
C How to program (8th edition) 6.15 (Duplicate Elimination) Use a one-dimension array to solve the following problem. Read in 20 numbers, each of which
C How to program (8th edition)
6.15 (Duplicate Elimination)
Use a one-dimension 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 diffrent. Use the smallest possible array to solce this problem.
help debugging and correcting code to compile and display non pduplicate values
#include
#define SIZE 20
int main()
{
int arrayList[SIZE] = { 0 };
int i;
int tDupli;
int count = 0;
int rDupli;
int value;
printf_s("Enter 20 numbers between 10 and 100(Inclusive): ");
for(i=0; i <= SIZE - 1; i++)
{
rDupli = 0;
scanf_s("%d", &value);
while (value < 10 || value >100)
{
puts(" ");
printf_s("Invalid Value. Re-Enter Value: ");
scanf_s("%d", &value);
}
for(tDupli = 0; tDupli < count; tDupli++)
{
if (value == arrayList[tDupli])
{
rDupli += 1;
break;
}
}
if (!rDupli)
{
arrayList[count++] = value;
}
}
puts(" ");
printf_s("Values that do not repeat are: ");
puts(" ");
for(i = 0; i < SIZE && arrayList[i] != 0; i++)
{
printf_s("%d ", arrayList[i]);
}
puts(" ");
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started