WAP for insert an element at desired position in an array?
#include <stdio.h>
int main()
{
int array[200], pos, a, n, val;
printf("Enter number of elements in array\n");
scanf("%d", &n);
printf("Enter %d elements\n", n);
for (a = 0; a< n; a++)
scanf("%d", &array[a]);
printf("Enter the location where you wish to insert an element\n");
scanf("%d", &pos);
printf("Enter the value to insert\n");
scanf("%d", &val);
for (a = n - 1; a >= pos - 1; a--)
array[a+1] = array[a];
array[pos-1] = val;
printf("Resultant array is\n");
for (a= 0; a<= n; a++)
printf("%d\n", array[a]);
return 0;
}
No comments:
Post a Comment