INSERT ELEMENT IN ARRAY USING FUNCTION

#include<stdio.h>
int insertele(int n)
{
    int a[1000] , pos, num , i , ele , p , q;

    num = n;
    printf(" Enter the %d arrayelements : ",n);
    for(i=0 ; i<num ; i++)
    {
        scanf("%d",&a[i]);
    }
    printf(" \n Enter the position to be inserted :");
    scanf("%d",&pos);

    printf("\n Enter the values to be inserted ");
    scanf("%d",&ele);

    p = num-1;
    q = pos-1;

    for(i=p; i>=q ; i--)
        a[i+1] = a[i];

    a[pos-1] = ele;

    printf(" \n The final arrayelement is :\t ");
    for(i=0 ; i<=num ; i++)
    {
        printf("%d\t",a[i]);
    }
    return 0;
}


int main()
{
    int n , x;

    printf(" Enter the number of elements : \t ");
    scanf("%d",&n);

    x = insertele(n);

    return 0;
}




OUTPUT : - 




For Other Programs Visit The WebSite:-   https://www.techapurba.com/


Follow Me On Social Media :-

For tech related videos visit my other website :- https://apurbatechinfo.blogspot.com/

Post a Comment

0 Comments