-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoveElement.c
More file actions
43 lines (39 loc) · 1.08 KB
/
Copy pathremoveElement.c
File metadata and controls
43 lines (39 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*Author : Anna Tony
Date : 26-02-2025
Description :function removeElement that takes an array,
its size, and the element to be removed as arguments.
Display the final result in the main function
Version : 1.0 */
#include<stdio.h>
void removeElement(int[],int*,int);
int main(){
int n,elementToRemove;
printf("Enter the size of the array : ");
scanf("%d", &n);
int array[n];
printf("Enter the elements : ");
for(int i=0;i<n;i++){
scanf("%d",&array[i]);
}
printf("Enter the element to remove : ");
scanf("%d", &elementToRemove);
removeElement(array,&n,elementToRemove);
printf("Final array after removing %d : ",elementToRemove);
for(int i=0;i<n;i++){
printf("%d ",array[i]);
}
return 0;
}
void removeElement(int array[],int *size,int remove){
int i,j;
while(i< *size){
if(array[i]==remove){
for(j=i;j< *size;j++){
array[j]=array[j+1];
}
(*size)--;
}else{
i++;
}
}
}