Array Deletion

Description:

Write a program to delete an element from the array. Input and Output Format: Assume that the maximum number of elements in the array is 20. Refer sample input and output for formatting specifications. All text in bold corresponds to input and the rest corresponds to output. Input: 1. The number of inputs to be entered by the user 2. The array elements 3. The array index to be deleted Example 1: Input 1: 4 11 12 13 14 1 Output 1: Array after deletion is 11 13 14 Explanation: Array Index starts from 0 the user entered array index as 1 so the number 12 is deleted. arr[0]=11 arr[1]=12 arr[2]=13 arr[3]=13 Deleted Element=12 a[1] Test Case 1 Input (stdin) 5 14 25 13 34 45 4 Expected Output Array after deletion is 14 25 13 34 Test Case 2 Input (stdin) 5 1 2 3 4 5 2 Expected Output Array after deletion is 1 2 4 5

Program :

#include<stdio.h>

 

int main()

{

    int a[100],i,n,pos;  

    scanf("%d",&n);

   

   

    for (i=0;i<n;i++)

    {

        scanf("%d",&a[i]);

    }

   

   

 

   

    scanf("%d",&pos);

    for(i=pos;i<n-1;i++)

    {

        a[i]=a[i+1];

    }

    n=n-1;

    printf("Array after deletion is\n");

    for(i=0;i<n;i++)

    {

        printf("%d ",a[i]);

    }

  return 0;

}