title: Menu driven program in c to perform various operations on an array
body: <p>Following is my c program that performs various operations on an array.When i delete any element the delete_ele function deletes and displays the array correctly, but the traverse function displays some garbage value. Eg. If initially i have 4 elements and delete the first element, the delete_ele function will display the remaining 3 elements but the traverse function displays 4 elements(remaining 3 elements along with a garbage value at the end). Please tell me the error. </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;conio.h&gt;
  void insert_ele(int i,int ar[],int len){
      int ele, loc;
      printf("\nEnter element to be inserted : ");
      scanf("%d",&amp;ele);
      printf("\nEnter location : ");
      scanf("%d",&amp;loc);
      if(i==19){
          printf("\nOverflow");
      }
      else{
          while(i&gt;=loc){
              ar[i+1]=ar[i];
              i--;
          }
      ar[loc]=ele;
      len++;
      printf("\nNew Array : ");
      for(i=0;i&lt;len;i++){
          printf("\t%d",ar[i]);
      }
      }
  }
  void delete_ele(int i,int ar[],int len){
      int loc;
      printf("\nEnter location of element to be deleted : ");
      scanf("%d",&amp;loc);
      if(len==0){
          printf("\nUnderflow");
      }
      else{
          for(i=loc;i&lt;len;i++){
              ar[i]=ar[i+1];
          }
          len--;
          printf("\nNew Array : ");
          for(i=0;i&lt;len;i++){
          printf("\t%d",ar[i]);
          }
      }
  }
  void find_ele(int i,int ar[],int len){
      int ele, count=0;
      printf("\nEnter element to be searched : ");
      scanf("%d",&amp;ele);
      for(i=0;i&lt;len;i++){
          if(ar[i]==ele){
              count++;
          }
      }
      if(count == 0){
          printf("\nElement does not exist");
      }
      else{
          printf("\nElement found %d times",count);
      }
  }
  void traverse(int i, int ar[], int len){
      printf("\nTotal number of Elements are : %d",len);
      printf("\nElements are : ");
      for(i=0; i&lt;len; i++){
          printf("\t%d",ar[i]);
      }
  }
  void main(){
      int ar[20], i=0, len=0, ch;
      char choice;
      clrscr();
      printf("\nEnter number of elements you want to insert : ");
      scanf("%d",&amp;len);
      for(i=0; i&lt;len; i++){
          printf("Enter element %d : ",i);
          scanf("%d",&amp;ar[i]);
      }
      i--;
      label:
      printf("\nPress 1 to insert, 2 to delete, 3 to find any element");
      printf("\n or 4 to traverse the array : ");
      scanf("%d",&amp;ch);
      switch(ch){
          case 1:insert_ele(i, ar, len);
          break;
          case 2:delete_ele(i, ar, len);
          break;
          case 3:find_ele(i, ar, len);
          break;
          case 4:traverse(i, ar, len);
          break;
          default:printf("\nInvalid Option");
          break;
      }
      printf("\nPress y to continue or any other key to quit : ");
      scanf("%s",&amp;choice);
      if(choice=='y' || choice=='Y'){
          goto label;
      }
      getch();
  }
  </code></pre>