Insert element in arr

 // Online C++ compiler to run C++ program online

#include <iostream>

using namespace std;


int insert(int *arr,int n,int cap,int x,int index){

    if (cap==n){

        return n;

    }

    for (int i=n;i>index;i--){

        arr[i]=arr[i-1];

        

    }

    arr[index]=x;

    n++;

    for (int i=0;i<n;i++){

        cout<<arr[i]<<" ";

    }

    return n;

}


int main() {

    int cap=5;

    int x;

    //cin>>x;

    int index;

    //cin>>index;

    int arr[5]={1,2,3};

    insert(arr,3,5,10,0);

    

    

    

    


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings