It's the first time I'm working with arrays so I'm trying to do some exercises on my school book. The assignment goes by:
Store 10 numbers in an array, print each one of them without printing the same number twice.
Examples:
array values: 1, 2, 4, 6, 3, 7, 8, 44, 2,1
printable values: 1, 2, 4, 6, 3, 7, 8, 44
I managed to make a for loop to store each one of the 10 values in the array, but I cant figure out how to check the values stored between one another.
my code so far.
int main()
{
int array[10], values[10], i;
printf("insert 10 integers:");
for(i=0; i<10; i++)
{
printf("\n");
scanf("%d", &array[i]);
}
return 0;
}
I tried thinking of using a variable to store the values in, while the actual ones in the array changes, so that I can do a selection and check if the new value is equal/different than the variable. But to do so I would have to include the variable in the loop, which would make it all useless because the new variable will always be equal to the new input.
EDIT 1:
int main()
{
int array[10], values[10], i, a=1;
printf("insert 10 integers:");
for(i=0; i<10; i++)
{
printf("\n");
scanf("%d", &array[i]);
a=i-1;
if(array[i]!=array[a])
{
values[i]=array[i];
}
}
for(i=0; i<10; i++)
{
printf("\n%d", values[i]);
}
return 0;
}
I wrote this new portion of code that is actually printing the values of the array without printing again the ones equal to one another. To do so I thought of using a new index, 'a' that will always be less by 1 than 'i', the first index. Except that i still prints 10 numbers and substitutes the removed values with random values