navigation

Deletion program in C

We can delete element at run time , as given in following program

/*
   This is a program for Deletion
   Date : 21 April 2014
   Time : 10:10 AM

*/
#include<stdio.h>
#include<conio.h>
#define max_size 10
int main()
{
     int arr[max_size],no,tmp_no,i,f=0;
     char ch;
     start:
     printf("\nEnter How many Number do you want to insert out of %d : ",max_size);
     scanf("%d",&no);
     if(no>max_size){
       printf("\nSorry you have only %d Maximum size ",max_size);
       printf("\nPlease Try Again : ");
       goto start;
     }
     for(i=0;i<no;i++)
     {
        printf("Enter Number  %d : ",i+1);
        scanf("%d",&arr[i]);
     }              
     do{
        printf("\nYour Array is : ");            
        for(i=0;i<no;i++)
         {
          printf("\n Number %d : %d",i+1,arr[i]);              
         }
       if(no==0){
            printf("\nArray UnderFlow ");
            break;
             }
        printf("\nEnter a Number to Delete : ");
        scanf("%d",&tmp_no);
        for(i=0;i<no;i++){
                 if(arr[i]==tmp_no){
                    arr[i]=0;
                    while(i<no){
                        arr[i]=arr[i+1];
                        i++;
                        }            
                      no--;
                      printf("Deleted Successfully !!");
                      f=1;
                      break;                 
             }        
         }
         if(f==0){
             printf("\nNumber Not Found !!");
              }
         printf("\nDo you want to insert more (y/n) : ");
        ch=getche();
     }while(ch=='y' || ch =='Y');
     printf("\nThanks For visiting for more please Visit http://latestfaq.blogspot.in/");
     getch();
     return 0;
     }


Download Source File : Deletion.c
other impotent links :  Insertion in array, Insertion and deletion in array.binary search.
keywords : Deletion in array, delete an element from array, insertion and deletion program in c.
Deletion program in C Deletion program in C Reviewed by Unknown on 22:40 Rating: 5

No comments:

Powered by Blogger.