MENU
Question -

Write a function SWAP2 CHANGE (int P[], int N) in C++ to modify the content of the array in such a way that the elements, which are multiples of 10 swap with the value present in the very next position in the array.
For example:
If the content of array P is
91,50,54,22,30,54
The content of array P should become
91,54,50,22,54,30



Answer -

 void SWAP 2CHANGE (int P[], int N)
 {
 for (int i=0; i
 {
 if (P [i]% 10==0)
 {
 int temp=0;
 temp=P[i];
 P[i]=P [i+1] ;
 P[i+1]=temp;
 i++; //Go to next element
 }
 }
 }

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
×