Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
1.4 kB
3
Indexable
Never
#include<stdio.h>
#define max 10
int a[max];
void  insert(int *a,int *n){
    int e,p;
    printf("Enter ele and pos to insert:\n");
    scanf("%d%d",&e,&p);
    n++; 
    for(int i=n-1;i>=p-1;i--){
        a[i]=a[i-1];
    }  
    a[p-1]=e;
}
void delete(int n){
    int e,p;
    printf("Enter ele and pos to remove:\n");
    scanf("%d%d",&e,&p);
}
void search(int n){
    int e,s=0;
    printf("Enter ele to be searched:\n");
    scanf("%d",&e);
    for(int i=0;i<n;i++){
        if(a[i]==e) s++;
    }  
    if(s>0) printf("Element found!\n");
    else  printf("Element not found!\n");
}
void disply(int *a,int *n){
    for(int i=0;i<n;i++){
        printf("%d\t\n",a[i]);
    }
}
void main(){
    int i,choice,n;
    printf("Enter size of the array:");
    scanf("%d",&n);
    printf("Enter elements:\n");
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        int *arr=&a[0];
        int *ptr=&n;
    while(1){
        printf("1 -> Insert\n");
        printf("2 -> Delete\n");
        printf("3 -> Search\n");
        printf("4 -> Display\n");
        printf("Enter your choice: ");
        scanf("%d",&choice);
        switch(choice){
            case 1 :insert(arr,ptr);break;
            case 2 :delete(n);break;
            case 3 :search(n);break;
            case 4 :disply(arr,ptr);break;
            default : printf("INVALID\n");
        }
    }
}
Leave a Comment