Created
November 21, 2017 08:15
-
-
Save awave1/005ffc0b347e3ca0447673c039cd68bd to your computer and use it in GitHub Desktop.
remove element from array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define SIZE 12 | |
int main() { | |
int arr[SIZE] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; | |
int size = SIZE; | |
int i = 0; | |
int pos = 4; | |
int sz = size - 1; | |
int i_next = 0; | |
// show defaulp array | |
for (i = 0; i < size; i++) | |
printf("%d\t", arr[i]); | |
printf("\n\n"); | |
for (i = pos - 1; i < sz; i++) { | |
i_next = i + 1; | |
printf("i = %d\n", i); | |
arr[i] = arr[i_next]; | |
} | |
printf("\n\n"); | |
// update the size | |
size--; | |
// print new array | |
for (i = 0; i < size; i++) | |
printf("%d\t", arr[i]); | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment