Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void main( )
- {
- int a[20],n,item,i;
- printf("Enter the size of the array");
- scanf("%d",&n);
- printf("Enter elements of the array in the sorted order");
- for(i=0; i<n; i++)
- {
- scanf("%d", &a[i]);
- }
- printf("nEnter ITEM to be inserted : ");
- scanf("%d", &item);
- i = n-1;
- while(item<a[i] && i>=0)
- {
- a[i+1] = a[i];
- i--;
- }
- a[i+1] = item;
- n++;
- printf("nnAfter insertion array is :n");
- for(i=0; i<n; i++)
- {
- printf("n%d", a[i]);
- }
- getch();
- }
- #include <stdio.h>
- int main()
- {
- int array[100], position, c, n, value;
- printf("Enter number of elements in arrayn");
- scanf("%d", &n);
- printf("Enter %d elementsn", n);
- for (c = 0; c < n; c++)
- scanf("%d", &array[c]);
- printf("Enter the location where you wish to insert an elementn");
- scanf("%d", &position);
- printf("Enter the value to insertn");
- scanf("%d", &value);
- for (c = n - 1; c >= position - 1; c--)
- array[c+1] = array[c];
- array[position-1] = value;
- printf("Resultant array isn");
- for (c = 0; c <= n; c++)
- printf("%dn", array[c]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement