Deitel & Deitel, C How to Program 6th Edition, Exercise 6.15 (Duplicate Elimination)
/*6.15 (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.*/
#include <stdio.h>
int search(int a[], int, int);
int main() {
int i, arr[20] = {0}, j, duplicate = 0;
for (i = 0; i < 20; i++) {
scanf("%d", &arr[i]);
for (j = 0; j < i; j++)
if (arr[i] == arr[j])
duplicate = 1;
if (duplicate == 0) {
printf("VOOOV A NEW NUMBER <3 %d\n", arr[i]);
}
duplicate = 0;
}
return 0;
}
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.*/
#include <stdio.h>
int search(int a[], int, int);
int main() {
int i, arr[20] = {0}, j, duplicate = 0;
for (i = 0; i < 20; i++) {
scanf("%d", &arr[i]);
for (j = 0; j < i; j++)
if (arr[i] == arr[j])
duplicate = 1;
if (duplicate == 0) {
printf("VOOOV A NEW NUMBER <3 %d\n", arr[i]);
}
duplicate = 0;
}
return 0;
}
Let me know in the comments if this page helped you somehow.
It is nice to know if my work helped someone, thanks :)
Output
ReplyDelete