swapping the alternate values in given array's element ! 17/11/2022

 #include <iostream>

using namespace std ;

// funtion to print the value of array;
void printingarray(int arr[],int size){
for (int i = 0; i < size; i++){
cout<<arr[i]<<" ";
}
{
/* code */
}
}

// funtion to swap the alternate value of an arra's element;
void alternetswap(int arr[],int size){
for (int i = 0; i < size; i+=2)
{
if (i+1<size)
{
swap(arr[i],arr[i+1]);
}
}
}

int main(){

int marry[6]={1,2,3,4,5,6};
int garry[5]={23,43,56,76,4};


alternetswap(marry,6);
printingarray(marry,6);

cout<<endl;
alternetswap(garry,5);
printingarray(garry,5);

}

Comments

Popular posts from this blog

Learning stage | c++ programs

c++ basic question