Need Help i got this assignment to create a program to insert element in array, delete element in array and view elements in array by using Menu Driven Programs
plz help me

Recommended Answers

All 7 Replies

Of course we are able to help you. Could you show us your code and point out what issue you are having?

Member Avatar for SoreComet

You could create a Menu like this

  1. Insert Element
  2. Delete Element
  3. Display

Now get the input from the user.
If the user gives the input as 1, that is Insert. Call the insert function
If the user gives the input as 2, that is Delete. Call the Delete function
If the user gives the input as 3, that is Display. Call the Display function

printf(" 1. Insert\n 2. Delete\n 3. Display");
scanf("%d",Choice that you want to execute);

Use Switch..Case code to use Menu driven program

switch(choice you want)
{
    case 1:
        //INSERT
        break;
    case 2:
        //DELETE
        break;
    case 3:
        //DISPLAY
        break;
}

Hope this helps :)

Hey ladis thanks a lot i finally created this
plz review dis and if der is any error or suggestion let me know
srry for ma english

#include<stdio.h>
#include<conio.h>
int insert(int *);
int view(int *);
int del(int *);
void main()
{
    int a[100];
    int ch;
    while(1)
    {
    clrscr();
    {
    printf("\nEnter 1 to insert element in array:\t");
    printf("\nEnter 2 to view element in array:\t");
    printf("\nEnter 3 to Delete element in array:\t");
    printf("\nEnter 4 to Exit:\t");
    printf("\n enter the choice \n");
    scanf("%d",&ch);
    switch(ch)
    {
        case 1:insert(a);getch();
                    break;
        case 2:view(a);getch();
                    break;
        case 3:del(a);getch();
                    break;
        case 4:exit(0);
    }
    }
    }

}
int insert(int *a)
{
    int i,n;
    printf("Enter the no. of elements in array:\t");
    scanf("%d",&n);
    printf("\nEnter %d elements in array:\t",n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    a[i]='\0';
    return *a;
}
int view(int *a)
{
    int j;
    for(j=0;a[j]!=NULL;j++)
    {
        printf("\nElement of array=%d",a[j]);
    }
    return *a;
}
int del(int *a)
{
    int c,k,posi;
    for(k=0;a[k]!=NULL;k++)
    {
    }
    printf("Enter the position to delete element:\t");
    scanf("%d",&posi);
    if(posi<=k)
    {
        for(c=posi-1;c<k-1;c++)
        {
            a[c]=a[c+1];
        }
        printf("\nArray after Deletion");
        for(c=0;c<k-1;c++)
        {
            printf("\n%d",a[c]);
        }
    }
    return *a;
}
commented: Very poor design..and not platform independent +0

Read this and figure out why you must not use void main() but int main(void). "A-void main()" (Read as: avoid void main()) Didn't look further though.

commented: I rather saw conio.h & stopped +1
Member Avatar for SoreComet

Hi Viksat07,

Sorry I couldn't reply you soon.

Well, a good working program indeed. But you have check out the Change in Array Limit once you have DELETED an element from the array.
If you display your Array without decrementing the Array limit by one, then the last element will be displayed twice.
You could do that by changing the final value of the Array to NULL

 for(c=posi-1;c<k-1;c++)
 {
    a[c]=a[c+1];
 }

 /*Check if a[c] = NULL and if NULL make a[c-1] = NULL*/

 if(a[c] == NULL)
 {
     a[c-1] = NULL;
 }

 printf("\nArray after Deletion");
 for(c=0;c<k-1;c++)
 {
    printf("\n%d",a[c]);
 }

Hope this helps you

can you help me with this program using bluej
wap to enter an element and delete that element from the array and display the resultant array

commented: dont solve your homework here +0

Please send the output of this program

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.