Home why are step and j 'C' Variables changing their values on their own?

# why are step and j 'C' Variables changing their values on their own?

himanscience
1#
himanscience Published in 2018-02-13 15:11:45Z
 the j and step value changes wierdly at the endThe step and j variables are changing their values in the do-while loop. I have added the printfs to check the values of those variables.And at the last iteration j and step change their valuesThe step and j variables are changing their values in the do-while loop. I have added the printfs to check the values of those variables.And at the last iteration j and step change their values  #include int main() { int arr[9] = {53, 7, 0, 21, 43, 35, 75, 4, 1}; int len = 9; int step = len / 2; int i,j,k, z; int cmps=0, movs = 0, temp; int asstep = 0; int count = 0; int unistep = step; while(step >= 1) { printf("ASSTEP: %d\n", asstep); for(j = 0; j < len; j++) { printf("%d ", arr[j]); } printf("\nstepu: %d", step); count = 0; asstep = 0; //int unistep = step; while(count < step) { //creating groups int tarr[unistep]; j = asstep; int stepvalue = asstep; int temp = step; z = 0; do { printf("len:%d j:%d step:%d\n",len, j, step); tarr[z] = arr[j]; z++; j = j + step; printf("len:%d j:%d step:%d\n",len, j, step); } while(j < len); step = temp; //asstep++; for(j = 0; j < step; j++) { printf("%d ", tarr[j]); } printf("\n"); count++; //ends //applying insertion sort int y; for(y = 0; y < z; y++) { //printf("%d ", tarr[y]); for(k = y; k < y + 1; k++) { int o; for(o = 0; o < k; o++) { cmps++; if(tarr[k] < tarr[o]) { printf(" k:%d o:%d", tarr[k], tarr[o]); temp = tarr[k]; movs++; int a; for(a = y; a > o; a--) { tarr[a] = tarr[a-1]; movs++; //printf(" d:%d", arr[a-1]); } tarr[o] = temp; movs++; break; } } } int e; printf("insertion\n"); for(e = 0; e < z; e++) { printf("%d ", tarr[e]); } printf("\n"); } //ends j = asstep; stepvalue = asstep; z = 0; while(j < len) { if(j < len) { //tarr[z] = arr[j]; arr[j] = tarr[z]; printf("tarr%d z%d stepv%d\n", tarr[z], z, stepvalue); z++; } j = j + step; } printf("asstep: %d", asstep); asstep++ ; } step = step / 2; printf("step: %d\n", step); } for(j = 0; j < len; j++) { printf("%d ", arr[j]); } printf("\n"); return 0; } 
 You need to login account before you can post.
Processed in 0.310658 second(s) , Gzip On .