C Program To Insert An Element In An Array


♣ Try it Out ::
#include<stdio.h>
#include<conio.h>

main()
{
    int Arr[101], Value, Size, i, pos;

    printf("How many numbers you wish to input in array: ");
    scanf("%d", &Size);

    printf("Enter %d integers: \n", Size);
    for(i=0; i<Size; i++)
        scanf("%d", &Arr[i]);

    printf("\nEnter position where you wish to insert an element: ");
    scanf("%d", &pos);

    printf("Enter the value to insert: ");
    scanf("%d", &Value);

    for(i=Size-1; i>=pos-1; i--)
        Arr[i+1] = Arr[i];

    Arr[pos-1] = Value;

    printf("\nResultant array is:\n");
    for(i=0; i<=Size; i++)
        printf("%d ", Arr[i]);

    getch();
    return(0);
}

♣ Output ::
How many numbers you wish to input in array: 5
Enter 5 integers:
4 2 3 9 7

Enter position where you wish to insert an element: 3
Enter the value to insert: 6

Resultant array is:
4 2 6 3 9 7

♣ Downloads ::

Comments

Popular posts from this blog

C++ :: Topological Sort Algorithm (using DFS)

How to Hack Facebook Account

C++ :: Strongly Connected Components Algorithm (SCC)