printing numbers

I have a problem printing only one of each number that the user inputs.
If the user inputs 20 number 10 it prints the 10 but also 19 other garbage numbers. How can i solve my issue?

Here is my code.


#include <stdio.h>
#include <stdlib.h>

int main()
{
printf("This program asks the user for 20 numbers between 10-100.\n"); // description of program
printf("Then detemines which numbers have been repeated\nand displays one of those numbers.\n\n");

int numbs[20], counter2, counter, size = 20; // variables

for(counter = 0; counter < size; counter++)
{
printf("Please enter 20 numbers between 10 - 100: "); // ask user for numbers
scanf("%d", &numbs[counter]);
}

for (counter = 0; counter < size; counter++)
{
for(counter2 = size ; counter2 > counter; counter2--)
if (numbs[counter] == numbs[counter2])
{
numbs[counter2] = numbs[counter2+1];
size--;
}
}

for (counter = 0; counter <= size; counter++)
{
printf("%d ",numbs[counter]); // print numbers
}

printf("\n\n");

return 0;

}
delete the equal sign in this part .

instead of this:

for (counter = 0; counter <= size; counter++)

do this:

for (counter = 0; counter < size; counter++)
Thank you
ur welcome :)
Last edited on
Topic archived. No new replies allowed.