100% program to delete a element from given location in the array


#include <stdio.h>
void main()
{
    int a[20],i,n,location;
    printf("\n enter no of elements in the array with max limit of 20:");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("\n enter the (integer) element a[%d]:",i);
        scanf("%d",&a[i]);
    }
    printf("\n enter the location of the element to be deleted:");
    scanf("%d",&location);
    for(i=location-1;i<n;i++)
     a[i]=a[i+1]; //shifting the elements
   
    printf("\n the elements in the array after deletion of 1 element are:\n");
    for(i=0;i<n-1;i++) // now the array size decreased by 1 so (n-1)
     printf("a[%d]=%-4d    ",i,a[i]);
}     

తెరమీద 
enter no of elements in the array with max limit of 20:4
enter the (integer) element a[0]:2
enter the (integer) element a[1]:5
enter the (integer) element a[2]:8
enter the (integer) element a[3]:-1
enter the location of the element to be deleted:3
the elements in the array after deletion of 1 element are:
a[0]=2       a[1]=5       a[2]=-1      

కామెంట్‌లు

ఈ బ్లాగ్ నుండి ప్రసిద్ధ పోస్ట్‌లు

100% C prog to write content into a file and then read it back onto the console

Spic macay

శ్రీరస్తు.. రామలింగ 18-1-24 (సూరసాని వారి ఆహ్వానము)