I'm recently watching C programming and we started with the fixes, there is an exercise where I have an N-size array with repeated numbers (entered by the user), what I'm asked to do is that the user enter a number and verify in the fix if it is found, in case it is so that it eliminates the position of the last repeated number (ex: 1 2 3 2 4>> 1 2 3 4), now if it only repeats once it eliminates directly. This last point I get, but when it comes to comparing if there are more repeated ends up doing anything, I send this to a new arrangement that is ours at the end. And well, that is a doubt / problem / situation, if someone were so kind to help me, I appreciate it. Greetings: D
[Edited]
int main(){
int arr[n],nuevo[n],i,j,x,nro,cont,band=0;
printf("Ingrese numeros, si son repetidos no importa\n");
for(i=0;i<n;i++){
printf("Ingrese el numero: ");
scanf("%i",&arr[i]);
}
printf("Ingrese un numero a eliminar: ");
scanf("%i",&nro);
for (i=0;i<n;i++) {
cont=0;
if(nro==arr[i]) cont++;
if(cont==1){
x=i;
while(x<n){
arr[x]=arr[x+1];
x++;
}
}
}
for (i=0;i<n-1;i++) printf ("%i ",arr[i]);
With this code what it does is eliminate the times that with the cont is 1, therefore it will always eliminate the same number to me, and what I want is that it is only the last position.