C# Saved Program: majestic-mountain

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <stdio.h>
void insert(int *a,int s);
void delte(int *a,int s);
void search(int *a,int s);
void display(int *a,int s);
int n=0;
int main()
{
    int *a,s,i,x;
    printf("enter the size of an array\n");
    scanf("%d",&s);
    a=(int *)malloc(s * sizeof(int));
    for(i=0;i<s;i++)
        a[i]=-1;
    while(1)
    {
        printf("choose any option from below\n");
        printf("1.insert an element\n");
        printf("2.delete an element\n");
        printf("3.search an element\n");
        printf("4.finding no.of elements\n");
        printf("5.display the elements\n");
        printf("6.exit\n");
        printf("please enter your option\n");
        scanf("%d",&x);
        switch(x)
        {
            case 1:
            insert(a,s);
            break;
            case 2:
            delte(a,s);
            break;
            case 3:
            search(a,s);
            break;
            case 4:
            printf("the no.of elements are %d",n);
            break;
            case 5:
            display(a,s);
            break;
            case 6:
            exit(1);
            break;
            default:
            printf("invalid option....please choose between 1 and 6\n");
            break;
        }
    }
}
void insert(int *a,int s)
{
    int pos,p;
    if(n==s)
        printf("sorry array is not empty\n");
    else
    {
        printf("enter the position whwre the element is to b inserted\n");
        scanf("%d",&pos);
        if(a[pos]!=-1)
            printf("sorry the position is not empty\n");
        else
        {
            printf("enter the element to b inserted\n");
            scanf("%d",&p);
            a[pos]=p;
            n++;
            printf("insertion is succesful\n");
        }
    }
}
void delte(int *a,int s)
{
    int pos;
    if(n==0)
        printf("the array is already empty\n");
    else
    {
        printf("enter the position where the element to be deleted\n");
        scanf("%d",&pos);
        if(a[pos]==-1)
            printf("the position is already empty\n");
        else
        {
            a[pos]=-1;
            n--;
            printf("deletion is succesful\n");
        }
    }
}
void search(int *a,int s)
{
    int key,i; 
    if(n==0)
        printf("sorry array is empty\n");
    else
    {
        printf("enter the element to b searched\n");
        scanf("%d",&key);
        for(i=0;i<s;i++)
        {
            if(a[i]==key)
            {
                printf("search found at %d",i);
                break;
            }
            else
            {
                printf("search not found\n");
                continue;
            }
        }
    }
}
void display(int *a,int s)
{
    int i;
    for(i=0;i<s;i++)
        printf("the elements are %d\n",a[i]);
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs