#include <stdio.h>
int main()
{
int array[20], t = 0; //20-t is the new size of array.
for(int i = 0; i<20; i++)
scanf("%d", &array[i]);
for(int i = 0; i<20-t; i++)
{
for(int j = i+1; j<20-t; j++)
{
if(array[i] == array[j])
{
for(int z = j; z<20-t; z++)
array[z] = array[z+1];//shift numbers.
t++;
i = -1;
}
}
}
}
This program works fine but I am not sure why it does when i = -1 but not when i = 0? I would also like to know the complexity of this code.
for(int i = 0; i<20-t; i++)
printf("%d ", array[i]); //Array after duplicates have been removed.
return 0;
}