Advertisement
Foyaj128

Menu4

Feb 11th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.17 KB | None | 0 0
  1. void display_Array(int b[],int k);
  2. void edit (int b[],int pp, int vv);
  3. int Insertion_lastpositon (int b[],int nn, int vv);
  4. int Insertion_specification (int b[],int nn, int vv,int pp);
  5. int Deletion (int b[], int nn, int pp);
  6. int main ()
  7.  
  8. {
  9.     int a[100],n,i,c,b=1,v,p;
  10.     printf("\n Enter how many values\n");
  11.     scanf("%d",&n);
  12.     printf("\n Enter Values\n");
  13.     for(i=1;i<=n;i++)
  14.     scanf("%d",&a[i]);
  15.  
  16.     while (b)
  17.     {
  18.         printf("\n...........menu.......\n");
  19.         printf("\n pres 0 for Quit\n");
  20.         printf("\n pres 1 for display\n");
  21.         printf("\n pres 2 for insertion at last position\n");
  22.         printf("\n pres 3 for insertion at specific position\n");
  23.         printf("\n pres 4 for delete from specific position\n");
  24.         printf("\n pres 5 for linear search\n");
  25.         printf("\n pres 6 for Bubble sort\n");
  26.         printf("\n pres 7 for Binary search\n");
  27.         printf("\n pres 8 for Edit\n");
  28.         printf ("\n Enter your choice\n");
  29.         scanf("%d", &c);
  30.  
  31.         switch(c)
  32.         {
  33.             case 0:b=0;
  34.             break;
  35.  
  36.             case 1:printf("\n choice=display\n");
  37.             if(n!=0)
  38.             display_Array(a,n);
  39.             else
  40.             printf("\n No data to display\n");
  41.             break;
  42.  
  43.  
  44.             default:printf("\n Wrong choice\n");
  45.             break;
  46.  
  47.             case 2: printf ("\n choice = Insertion at last position \n");
  48.             printf("Enter new value \n");
  49.             scanf ("%d",&v);
  50.             n=Insertion_lastpositon(a,n,v);
  51.             break;
  52.             case 3: printf("\n choice = insertion att specification\n");
  53.             if(n!=0)
  54.  
  55.             {
  56.  
  57.             K:printf("\n Enter position between %d to %d \n \n",1,n+1);
  58.             scanf("%d",&p);
  59.             if(p>=1 && p<=n+1)
  60.             {
  61.                 printf("\Enter new value \n");
  62.                 scanf("%d",&v);
  63.                 n=Insertion_specification(a,n,v,p);
  64.                 printf("\n\n inserted at position %d\n",p);
  65.             }
  66.             else
  67.             {
  68.                 printf("\n wrong position \n");
  69.                 goto K;
  70.             }
  71.             }
  72.             else
  73.             printf("\n the array is empty \n");
  74.             break;
  75.  
  76.             case 4: printf("\n Choice = Delete from Array \n");
  77.             if (n!=0)
  78.             {
  79.                 Z: printf("\n Enter Position between %d to %d\n",1,n);
  80.                 scanf("%d",&p);
  81.                 if (p>=1 && p<=n)
  82.                 {
  83.                 printf("\n Delected value = %d\n", a[p]);
  84.                 n=Deletion (a,n,p);
  85.                 printf ("\n Delete Sucessfully from position %d\n",p);
  86.                 }
  87.                 else
  88.                 {
  89.                     printf("\n Wrong position \n");
  90.                     goto Z;
  91.                 }
  92.             }
  93.             else
  94.             printf("\n No data to delete \n");
  95.             break;
  96.  
  97.  
  98.  
  99.             case 8:
  100.             printf("\n choice=edit\n");
  101.             if(n!=0)
  102.             {
  103.                 printf("\n Enter new value\n");
  104.                 scanf ("%d",&v);
  105.  
  106.  
  107.             M: printf ("enter position between %d to %d\n ",1,n);
  108.                 scanf("%d",&p);
  109.                 if(p>=1&& p<=n)
  110.                 edit (a,p,v);
  111.  
  112.                 else {
  113.                 printf ("\n wrong position\n");
  114.                 goto M;
  115.                      }
  116.  
  117.                      }
  118.  
  119.              else
  120.                 printf("No data to edit\n");
  121.                 break;
  122.  
  123.         }
  124.  
  125.     }
  126. }
  127. void display_Array(int b[],int k)
  128. {
  129.     int j;
  130.     printf("\n the values are:\n");
  131.     for(j=1;j<=k;j++)
  132.     printf("%d\n", b[j]);
  133.  
  134. }
  135.  
  136. void edit (int b[], int pp ,int vv)
  137. {
  138.     b[pp]=vv;
  139.     printf("\n edited successfully\n");
  140. }
  141. int Insertion_lastpositon (int b[],int nn, int vv)
  142. {
  143.     b[nn+1]=vv;
  144.     printf("\n Inserted Sucessfully \n\n");
  145.     return nn+1;
  146. }
  147. int Insertion_specification (int b[],int nn, int vv,int pp)
  148. {
  149.     int j;
  150.     for (j=nn;j>=pp;j--)
  151.     b[j+1]=b[j];
  152.     b[pp]=vv;
  153.     return nn+1;
  154. }
  155. int Deletion (int b[], int nn, int pp)
  156. {
  157.     int j;
  158.     for (j=pp; j<nn;j++)
  159.     b[j]=b[j+1];
  160.     return nn-1;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement