Write a program to swap two numbers in C++

Configurare noua (How To)

Situatie

We will use a temporary variable to store one of the numbers to perform the swap operation.

Backup

#include <iostream>
using namespace std;
int main() {
int a = 10;
int b = 20;
cout<<a<<" "<<b<<endl;
int temp = a;
a = b;
b = temp;
cout<<a<<" "<<b<<endl;
return 0;
}
Output: 10 20
20 10

Solutie

Tip solutie

Permanent

Voteaza

(4 din 8 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?