Advertisement
Mamun23

data-add-delete-insarition

Feb 11th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.58 KB | None | 0 0
  1. #include<stdio.h>
  2. //FUNCTION DECLARATION
  3. void DisplayArray(int b[],int k);
  4. void Edit(int b[], int pp, int vv);
  5. int InsertLastPos(int b[],int nn,int vv);
  6. int Inserttion_SpecificPos(int b[],int nn, int vv,int pp);
  7. int deletion (int b[],int nn, int pp);
  8. int main()
  9. {
  10.     int a[100],n,i,c, b=1,v,p;
  11.     printf("Enter How Many Values: \n");
  12.     scanf("%d",&n);
  13.     printf("Enter Values:");
  14.  
  15.     for (i=1; i<=n; i++)
  16.  
  17.         scanf("%d", &a[i]);
  18.  
  19.     while(b)
  20.     {
  21.        printf("--------Menu--------\n");
  22.        printf("\nPress 1 for Display \n");
  23.        printf("\nPress 2 for Insertion at Last Point \n");
  24.        printf("\nPress 3 for Insertion at Specific Point \n");
  25.        printf("\nPress 4 for Delete from Specific Position \n");
  26.        printf("\nPress 5 for Linear Search \n");
  27.        printf("\nPress 6 Bubble Sort \n");
  28.        printf("\nPress 7 for Binary Search \n");
  29.        printf("\nPress 8 for Edit \n");
  30.        printf("\nPress 0 for Quit \n");
  31.        printf("\nEnter Your Choice: ");
  32.        scanf("%d",&c);
  33.  
  34.        switch (c)
  35.        {
  36.            //QUIT
  37.         case 0: b=0;
  38.            break;
  39.  
  40.            //DISPLAY
  41.         case 1:
  42.            printf("\n You have Choiced Display\n");
  43.            if(n!=0)
  44.  
  45.            DisplayArray(a,n);
  46.            else
  47.            printf("\n There Are No Data to Display\n ");
  48.            break;
  49.  
  50.            //INSERTION AT LAST POSITION
  51.         case 2:
  52.            printf("\nYou Have Choiced Insert at Last Postition\n");
  53.            printf("\nEnter Value\n");
  54.            scanf("%d",&v);
  55.            n = InsertLastPos(a,n,v);
  56.            break;
  57.  
  58.           //Insertion at spcific Position
  59.     case 3:    printf("\n choice= insertion at specifition\n");
  60.                if(n!=0)
  61.             {
  62.         k:       printf("\n Enter position between %d to %d \n", 1, n+1);
  63.                scanf ("%d",&p);
  64.                if (p>=1 && p<=n+1)
  65.                {
  66.                    printf("\n Enter new valu \n");
  67.                    scanf("%d",&v);
  68.                    {
  69.                    printf("\ninsartion value is=%d\n",v);
  70.                    n=Inserttion_SpecificPos(a,n,v,p);
  71.                    printf("\n insartion position is %d\n",p);
  72.                    }
  73.                }
  74.                else
  75.                {
  76.                    printf("\n wrong position \n");
  77.                    goto k;
  78.                }
  79.            }
  80.            else
  81.            printf ("\n the array is emptu \n");
  82.            break;
  83.  
  84. //delete
  85. case  4:
  86.         printf("\n choice= Delete form array \n");
  87.         if (n!=0)
  88.         {
  89.             z: printf("\n Enter position between %d to %d\n ", 1 ,n);
  90.             scanf("%d",& p);
  91.             if (p>=1 && p<=n)
  92.             {
  93.             printf("\ndeleted value is=%d\n",a[p]);
  94.             n=deletion(a,n,p);
  95.             printf("\n deleted position is %d\n",p);
  96.             }
  97.             else
  98.             {
  99.                 printf("\n wrong position \n");
  100.                 goto z;
  101.             }
  102.         }
  103.         else
  104.         printf("\n no data to delete \n");
  105.         break;
  106.  
  107.            //EDIT
  108.         case 8:
  109.            printf("\nYou have Choiced Edit");
  110.            if(n!=0)
  111.            {
  112.                printf("\nEnter new Value\n");
  113.                scanf("%d",&v);
  114.               M:printf("Enter Position between %d to %d\n",1,n);
  115.                scanf("%d",&p);
  116.                if(p>=1 && p<=n)
  117.                Edit(a,p,v);
  118.                else
  119.                {
  120.                    printf("\nWrong Position\n");
  121.                    goto M;
  122.                }
  123.            }
  124.            else
  125.            printf("\nNo Data to Edit\n");
  126.            break;
  127.  
  128.  
  129.            default: printf("\n Wrong Choice \n");
  130.            break;
  131.        }
  132.     }
  133.         return 0;
  134. }
  135. //Dfinition of Function
  136.  
  137. //Display
  138. void DisplayArray(int b[],int k)
  139. {
  140.     int j;
  141.     printf("\n The values are:\n");
  142.     for (j=1; j<=k; j++)
  143.     printf("%d\n",b[j]);
  144. }
  145.  
  146. //Edit
  147. void Edit(int b[], int pp, int vv)
  148. {
  149.     b[pp]=vv;
  150.     printf("\nEdited Successfully\n");
  151. }
  152.  
  153. //Insertion at Last Position
  154. int InsertLastPos(int b[],int nn,int vv)
  155. {
  156.     b[nn+1]=vv;
  157.     printf("\nInserted Successfully\n");
  158.     return nn+1;
  159. }
  160.  
  161. //Insertion at spcific Position
  162. int Inserttion_SpecificPos(int b[],int nn, int vv,int pp)
  163.  
  164. {
  165.     int j;
  166.     for (j=nn; j>=pp; j--)
  167.     b[j+1]=b[j];
  168.     b[pp]=vv;
  169.      printf("\n insertion is sucessfull\n");
  170.     return nn+1;
  171.  
  172. }
  173.  
  174. //delete at position
  175. int deletion (int b[],int nn, int pp)
  176. {
  177.     int j;
  178.     for (j=pp; j<nn; j++)
  179.     b[j]=b[j+1];
  180.      printf("\n Delete is sucessfull\n");
  181.     return nn-1;
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement