For this program is have to first input a list of up to 10 positive integers and end with -1, then enter another list of up to 10 positive integers and end with -1. Therecan be duplicate numbers in the list and the numbers are not in any particular order. There can be numbers inthe second list that are also in the first list.
the program is to print a list, in ascending order, of all the unique values that appear in these lists.
I have been able to make it so that the user enters both lists and ends with -1, but I can figure out how to get the unique values to print.
This is what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int arrayOne[10];
int arrayTwo[10];
int k, x, y, z;
int counter = 1, dupCounter = 1;
int swap;
setvbuf(stdout, NULL, _IONBF, 0);
printf("Enter first list of positive numbers: \n");
for (x = 0; x < 10; x++) {
scanf("%d", &arrayOne[x]);
if ((arrayOne[x]) == -1)
break;
counter = counter + 1;
}
printf("Enter second list of positive numbers: \n");
for (y = 0; y < 10; y++) {
scanf("%d", &arrayTwo[y]);
if ((arrayTwo[y]) == -1)
break;
dupCounter = dupCounter + 1;
}
//sort numbers
for (x = 0; x < counter - 1; x++) {
for (y = 0; y < counter - x - 1; y++) {
if (arrayOne[y] > arrayOne[y + 1]) {
swap = arrayOne[y];
arrayOne[y] = arrayOne[y + 1];
arrayOne[y + 1] = swap;
}
}
}
for (x = 0; x < counter; x++) {
for (y = 0; y < dupCounter; y++) {
if ((arrayOne[x]) != (arrayTwo[y])) {
printf("%d %d ", arrayOne[x], arrayTwo[y]);
}
}
}
return EXIT_SUCCESS;
}