### Need help on FOR loops :(

Hey guys! I need help! I'm kinda new here so i'll cut the to the crap.
I need to make a FOR loop for an array of 5 elements. (array[5]). The loop should pick the positions [1] and [4] and removes the integers positioned in it and the integers next to it should fill in the space like this:

Elements in Array:
23 24 25 26 27

Elements after deletion:
23 25 26 0 0

I'm having a hard time making one :((

oh, and here's the code i tried to make (so far, i keep on failing):

 ``1234567891011121314151617181920`` ``````#include #include int main() { void del(int*, int); int array[5] = {23,24,25,26,27}; int z = 5; del(array, z); getch(); } void del(arr, p) { int a = 0; for(a = 0; a < p; a++) { if ((a %2) == 0) printf("%d/n", a); } }``````
For loop is weird for an array of 5 when you have two cases, but here is the pseudocode for this:

 ``12345678`` ``````counter=0 for int a from 0 to less then 5 if a!=1 or a!=4 print array[a] else counter=counter+1 for i from 0 to less then counter print '0'``````
Last edited on
 ``1234567891011`` ``````void del( int a[], int n ) { int j = 0; for ( int i = 0; i < n; i++ ) { if ( a[i] % 2 == 0 ) a[j++] = a[i]; } for ( ; j < n; j++ ) a[j] = 0; }``````
Last edited on
Topic archived. No new replies allowed.