(Duplicate Elimination) Use a one-dimensional array to solve the following probl
ID: 3783949 • Letter: #
Question
(Duplicate Elimination) Use a one-dimensional array to solve the following problem: Write an app that inputs five numbers, each of which is between 10 and 100, inclusive. As each number is read, display it only if it’s not a duplicate of a number already read. Provide for the “worst case,” in which all five numbers are different. Use the smallest possible array to solve this problem. Display the complete set of unique values input after the user inputs each new value. (Duplicate Elimination) Use a one-dimensional array to solve the following problem: Write an app that inputs five numbers, each of which is between 10 and 100, inclusive. As each number is read, display it only if it’s not a duplicate of a number already read. Provide for the “worst case,” in which all five numbers are different. Use the smallest possible array to solve this problem. Display the complete set of unique values input after the user inputs each new value.Explanation / Answer
#include<stdio.h>
#include<conio.h>
int main()
{
int array[5], comp[5], flag=0;
printf("Please enter any value between 10 to 100 ");
for (int i=0; i<5; i++)
{
scanf("%d", &arr[i]);
for(int j=0; j<=i; j++){
if(arr[i]==comp[j]){
flag=1;
break;
}
else
comp[j]=array[i];
if(!flag)
{
printf("%d ", array[i]);
}
}
if(flag!=0)
comp[j]=arr[i];
}
}
}
}
for(int j=0; j<5; j++){
printf("%d ", comp[j])
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.