Home » Sometech » WAP for the deletion of array element from a specific position.

WAP for the deletion of array element from a specific position.

#include <stdio.h>

#include<conio.h>

#define SIZE 20

void main()

{

   int i,n,pos;

    int nums[SIZE];

printf(“Enter how many elements ? “);

scanf(“%d”,&n);

printf(“Enter array elements : \n”);

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

{ printf(“nums[%d]=”,i);

  scanf(“%d”, &nums[i]);

 }

printf(“\nOriginal array is \n”);

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

     printf(“%d “, nums[i]);

printf(“\nEnter the position of deletion <=%d : “,n);

scanf(“%d”,&pos);

for(i=pos;i<n;i++) /*shift the elements*/

nums[i-1]=nums[i];

nums[n-1]=0; /*copy 0 in place of last element*/

printf(“\narray after deletion is \n”);

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

     printf(“%d “, nums[i]);

getch();

}

Advertisements

SoME Tech

Error: Twitter did not respond. Please wait a few minutes and refresh this page.

%d bloggers like this: