Write a program to print an array after deleting specific element from it

Write a program to print an array after deleting specific element from it.

  1. #include <stdio.h>

  2. void main()
  3. {
  4.     int arr[100], position, i, n;
  5.     
  6.     printf("Enter number of elements in array : ");
  7.     scanf("%d", &n);
  8.     
  9.     printf("Enter %d elements : ", n);
  10.     
  11.     for ( i=0 ; i < n ; i++ )
  12.     scanf("%d", &arr[i]);
  13.     
  14.     printf("Enter the position to delete element : ");
  15.     scanf("%d", &position);
  16.     
  17.     if ( position >= n+1 )    
  18.     printf("Deletion not possible.\n");
  19.     
  20.     else {
  21.         for ( i = position-1 ; i < n-1 ; i++ )
  22.         arr[i] = arr[i+1];
  23.         
  24.         printf("After deleting specific element is : ");
  25.         for(i = 0 ; i < n - 1 ; i++ )        
  26.         printf("%d\n", arr[i]);        
  27.     }
  28. }

একটি মন্তব্য পোস্ট করুন