Created
July 15, 2014 14:13
-
-
Save shinymimiq/34dc03600e6b905de73a to your computer and use it in GitHub Desktop.
Simple C function to remove a element in the array
This file contains hidden or 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> | |
void removeelement(int,int,int*); | |
int main(int argc, char *argv[]) { | |
int num = 20; | |
int list[num]; | |
for (int i = 0; i < num ; i++) { | |
list[i]=i; | |
} | |
removeelement(5,num,list); | |
for (int i=0; i<num-1; i++) { | |
printf("%d, ",list[i]); | |
} | |
} | |
void removeelement(int number, int num, int* list){ | |
int i = 0; | |
for (; i < num; i++) { | |
if(number == list[i]){ | |
break; | |
} | |
} | |
for (; i < num-1; i++) { | |
list[i]=list[i+1]; | |
} | |
num--; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment