100% program to insert a element from given location in the array
#include <stdio.h>
void main()
{
int a[20],i,n,location, nayA;
printf("\n enter no of elements in the array with max limit of 19:"); /*the max limit u enter should be 1 less than array size (of 20) used (here) in the initial declaration becoz after inserting the element overall size should not cross initially declared size, which is 20 here*/
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 where new element has to be inserted:");
scanf("%d",&location);
printf("\n enter the integer element to be inserted:");
scanf("%d",&nayA);
for(i=n;i>=location;i--)
a[i]=a[i-1]; //shifting the elements
a[location-1]=nayA;
printf("\n the elements in the array after deletion of 1 element are:\n");
for(i=0;i<=n;i++) // now the array size increased by 1
printf("a[%d]=%-4d ",i,a[i]);
}
తెరమీద
enter no of elements in the array with max limit of 19:4
enter the (integer) element a[0]:2enter the (integer) element a[1]:4
enter the (integer) element a[2]:7
enter the (integer) element a[3]:-1
enter the location where new element has to be inserted:
3
enter the integer element to be inserted:0
the elements in the array after deletion of 1 element are:
a[0]=2 a[1]=4 a[2]=0 a[3]=7 a[4]=-1
మరోసారి
enter no of elements in the array with max limit of 19:4enter the (integer) element a[0]:2
enter the (integer) element a[1]:5
enter the (integer) element a[2]:1
enter the (integer) element a[3]:-1
enter the location where new element has to be inserted:2
enter the integer element to be inserted:4
the elements in the array after deletion of 1 element are:
a[0]=2 a[1]=4 a[2]=5 a[3]=1 a[4]=-1
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.