Answers for "swap 2 numbers in an array c++"

C++
3

swap values in array c++

#include <algorithm>
#include <iostream>

using namespace std;

int main()
{
     int array[]={1, 2};
     cout<<array[0]<<" "<<array[1]<<endl;
     swap(array[0], array[1]);
     cout<<array[0]<<" "<<array[1];
     return 0;
}
Posted by: Guest on January-20-2021
-2

swap of two numbers in c++

#include<iostream>
using namespace std;
int main()
{
    
    int a,b;
    cin>>a>>b;
    swap(a,b);
    cout<<a<<" "<<b;
    return 0;
}
Posted by: Guest on October-20-2021

Browse Popular Code Answers by Language