Yes j has the same value, thank you for making me notice. Changed the code and also added data acceptance from user:
Code:#include <stdio.h>#include <stdlib.h> #define MAXVALUE 10 void compact (int[], int); int main() { int arrSeries[MAXVALUE], i=0; int arrLength = MAXVALUE; printf("Please enter %d numbers.\n", MAXVALUE); while(i != MAXVALUE) { scanf("%d", &arrSeries[i]); i++; } compact(arrSeries, arrLength); getchar(); return 0; } void compact(int arrSeries[], int arrLength) { int i, j= 0, counter=0, newArray[MAXVALUE]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; newArray[0]=arrSeries[0]; for(i = 0; i != arrLength; i++) { if(newArray[j] != arrSeries[i]) { newArray[++j] = arrSeries[i]; } } while(counter !=MAXVALUE) { printf("%d ", newArray[counter]); counter++; } printf("\nThe number of steps: %d", j); getchar(); }



19Likes
LinkBack URL
About LinkBacks
. Changed the code and also added data acceptance from user:



. 
. I know C# a bit and I know there is a function for the same