adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C to delete a given number from given array

Program in C to delete a given number from given array



#include<stdio.h>
  int main()
     {
     int i,a[20],n,d,j;
     printf("Enter the size of array:-");
     scanf("%d",&n);
     if(n>20)  
        {
           printf("Invalid array size.");
           return 0;
       }
     printf("Enter %d numbers:-",n);
     for(i=0;i<n;i++)
     scanf("%d",&a[i]);
     printf("Enter delete Number:-");
     scanf("%d",&d);
     for(i=0;i<n;i++)
      {
        if(a[i]==d)
        {
          for(j=i;j<n;j++)  //for delete number
          a[j]=a[j+1];
          break;
        }
      }
     if(i==n)
       {
         printf("%d is not present in entered array.",d);
         return 0;
       }
       printf("After delete:-");
       for(i=0;i<n-1;i++)
          printf("%3d",a[i]);   
     return 0;
  }
Output:-








Related Programs

  1.   Program in C++ to delete a given number from given array

Post a Comment

0 Comments