Devolop A C Program To Insert An Element Into An Array in Any Position
Devolop A C Program To Insert An Element Into An Array in Any Position
#include<conio.h>
#include<stdio.h>
int main()
{
int i,k=0,a[100],n,loc,b,j;
printf("enter the array size: ");
scanf("%d",&n);
printf("enter the element: ");
for(i=0;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("enter the location ");
scanf("%d",&loc);
loc=loc-1;
printf("enter the element::");
scanf("%d",&b);
for(j=n;j>=loc;j--)
{
a[j+1]=a[j];
}
a[loc]=b;
n=n+1;
printf("after implementation :\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
getch();
}
Output:
enter the array size: 4
enter the element : 1
2
3
4
5
enter the location : 3
enter the element:: 45
after implementation :
1
2
45
4
5
Devolop a C program to delete an element into an array in any position .
#include <stdio.h>
#include <conio.h>
int main()
{
int a[50],i,pos,size;
printf("\nEnter size of the array: ");
scanf("%d",&size);
printf("\nEnter %d elements in to the array: ",size);
for(i=0;i<size;i++)
scanf("%d",&a[i]);
printf("\nEnter position where to delete: ");
scanf("%d",&pos);
i=0;
while(i!=pos-1)
i++;
while(i<10)
{
a[i]=a[i+1];
i++;
}
size--;
for(i=0;i<size;i++)
printf(" after implementation : %d",a[i]);
getch();
}
OUTPUT
Enter size of the array :5
Enter 5 elements in to the array :4
2
5
3
6
Enter position where to delete :3
after implementation : 4 2 3 6
sorted array is
1
2
3
3
4
7
getch();
}
OUTPUT
DELHI
KOLKATA
21
22