+ 1

Explain anyone

#include <iostream> using namespace std; int main() { int array[]={1,3,5,7,8}; int i,k=3,j,n=5; int item=10;j=n; cout<<"original array element"<<endl; for(i=0;i<n;i++) { cout<<"array["<<i<<"]"<<array[i]<<endl; } n=n+1; while(j>=k) { array[j+1]=array[j]; j=j-1; } array[k]=item; for(i=0;i<n;i++){ cout<<"new array["<<i<<"]="<<array[i] <<endl; } return 0; }

5th Sep 2017, 12:30 PM
Ponraj Hbk
Ponraj Hbk - avatar
2 Answers
+ 5
n is 6 and k is 3 j is 5 j is decremented and array[6] = array[5] array[5]= array [4] array[4]= array [3] and array[k] = item // array[3] = 10
5th Sep 2017, 1:09 PM
Amar Dahake
+ 1
doubt is n=n+1; while(j>=k) { array[j+1]=array[j]; j=j-1; } array[k]=item; how it's working
5th Sep 2017, 12:34 PM
Ponraj Hbk
Ponraj Hbk - avatar