4
Contributors
6
Replies
43
Views
4 Years
Discussion Span
Last Post by anishv
Featured Replies
  • 1

    Read [this](http://www.gidnetwork.com/b-66.html) 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. Read More

0

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 :)

Edited by Ladis

-2

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;
}

Edited by viksat07

Comments
Very poor design..and not platform independent
1

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.

Edited by mvmalderen

Comments
I rather saw conio.h & stopped
0

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

Edited by Ladis: Snippet added

-1

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

Comments
dont solve your homework here
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.