#include<stdio.h
>
#include<stdlib.h
>
#include<conio.h
>
int arr[100],size;
void del_beg();
void del_pos();
void del_last();
void del();
void display();
int main(){
int ch;
printf("Enter the size of the array : ");
scanf("%d",&size);
printf("Enter the array elements one by one.....\n");
for(int i=0;i<size
;i++){
scanf("%d",&arr[i]);
}
while(1){
printf("\n\t\t1. Deletion at beginning\n\t\t2. Deletion at a given possition\n\t\t3. Deletion at last\n\t\t4. Delete by number\n\t\t5. Display\n\t\t6. Exit\n");
scanf("%d",&ch);
switch(ch){
case 1:
del_beg();
break;
case 2:
del_pos();
break;
case 3:
del_last();
break;
case 4:
del();
break;
case 5:
display();
break;
case 6:
exit(0);
break;
default:
printf("Invalid Choice.....Try Again.....\n");
}
}
}
void del_beg(){
printf("The fisrt element %d of the array is deleted.\n",arr[0]);
for(int i=0;i<size
;i++){
arr[i]=arr[i+1];
}
size--;
printf("Array After deletion.....\n");
for(int i=0;i<size
;i++){
printf("%d\t",arr[i]);
}
printf("\n");
}
void del_pos(){
int pos;
printf("Enter the location which element you want to delete : ");
scanf("%d",&pos);
if(pos<=size){
printf("The element at %d possition i.e. %d is deleted.\n",pos,arr[pos-1]);
for(int i=pos-1;i<=size;i++){
arr[i]=arr[i+1];
}
size--;
printf("Array After deletion.....\n");
for(int i=0;i<size
;i++){
printf("%d\t",arr[i]);
}
printf("\n");
}
else{
printf("Out of array range.\n");
}
}
void del_last(){
printf("The last element i.e. %d is deleted.\n",arr[size-1]);
for(int i=size;i<size+1
;i++){
arr[i]=arr[i+1];
}
size--;
printf("Array After deletion.....\n");
for(int i=0;i<size
;i++){
printf("%d\t",arr[i]);
}
printf("\n");
}
void del(){
int item,x=0,flag=0;
printf("Enter item to delete : ");
scanf("%d",&item);
for(int i=0;i<size
;i++){
if(arr[i]==item){
x=i;
flag=1;
break;
}
else{
flag=0;
}
}
if(flag==1){
printf("The element %d is deleted.\n",item);
for(int i=x;i<=size;i++){
arr[i]=arr[i+1];
}
size--;
printf("Array After deletion.....\n");
for(int i=0;i<size
;i++){
printf("%d\t",arr[i]);
}
printf("\n");
}
else{
printf("The entered element %d is not found in array list.\n",item);
}
}
void display(){
printf("The elements of array.....\n");
for(int i=0;i<size
;i++){
printf("%d\t",arr[i]);
}
printf("\n");
}
Wednesday, 22 November 2017
C Program to Delete Element from Array
Subscribe to:
Post Comments (Atom)
Python Program to find Fabonacci
fabtab={} def fabonacci(n): fabtab[0]=0 fabtab[1]=1 for i in range(2,n+1): fabtab[i]=fabtab[i-1]+fabtab[i-2] ...
-
#include stdio.h > #include stdlib.h > #include conio.h > int arr[100], size=0; void insert_beg(); void insert_pos(); void inser...
-
#include iostream> #include conio.h > using namespace std; int main() { int n,num,first=0,middle,last; ...
-
#include iostream > #include conio.h > using namespace std; int main() { float radius; double area; ...
No comments:
Post a Comment