#include <iostream>
using namespace std;
int main () {
int a = ;
int b = ;
cout<<"a="<<a<<",b="<<b<<endl;
a = a+b; ///a=7
b = a-b; ///b=3;
a = a-b; ///a=5
cout<<"a="<<a<<",b="<<b<<endl;
return ;
}

Output ：

a=3,b=5

a=5,b=3

Exchange two numbers without intermediate variables swap(a,b); More articles about

1. C Language bit operation -- Exchange two values without intermediate variables

1. Use addition and subtraction to exchange two values : #define SWAP(a, b) ((&(a) == &(b)) || \ (((a) -= (b)), ((b) += (a)), ((a) = ...

2. java Exchange two values without intermediate variables

public void changeVal(){ int a = 2; int b = 3; System.out.println(" Exchange before a:"+a+",b:&quo ...

3. c Language to exchange the value of two numbers

C Language to achieve the exchange of the value of two numbers , There are many ways , The details are as follows . Do not use intermediate variables : // Exclusive or , a^=b^=a^=b; a ^= b; b ^= a; a ^= b; // Addition and subtraction a = a + b; ...

4. Qt_C++ Exchange two numbers

During programming , Exchanging two numbers is a common way I use , Here's a simple move bool Widget::swap(int a, int b) { int temp =a; a= b; b = temp; } In this way, it's ...

5. Realization pow(int x, int y), namely x Of y Power ; XOR exchanges two numbers ;

problem 1: Realization pow(int x, int y) , namely x Of y Power x Of y To the power of y individual x Continuous flight , The code is as follows : #include <stdio.h> #include <stdlib.h ...

6. C Language exchanges the values of two numbers

#include<stdio.h> int main() { // Exchange the values of two numbers // Method 1 The best readability ; ; int temp ; temp = a; a = b; b = temp ...

7. 20140806 Exchange two numbers extern &ldquo;C&rdquo; usage

1. Exchange two numbers Method 1.a+b It's possible to cross the border a=a+b; b=a-b; a=a-b; Method 2 . Will not cross the border a=a^b b=a^b; a=a^b;   2.extern "C" usage ( ...

8. Several functions that exchange two numbers （swap function ） How to write and analyze

#include <iostream> using namespace std; /* Value passed , local variable a and b The value of is really calling swap0 Time has changed , When it's over , Their life cycle is over */ void sw ...

9. Exchange two numbers -c++ Realization

Today, I saw the small program to exchange values , There are a lot of them on the Internet , Sort it out ,, Because there are many references , Didn't give the links one by one , If the original author saw , You can leave a message , I'll add // example_1_6_function_swap.cpp : Define console applications ...

Random recommendation

1. UI and 3D Scenes need to respond to touch events at the same time

For example, fighting scenes ,UI and 3D Scenes need to respond to touch events at the same time , If you respond at the same time, there may be a touch UI It's affecting 3D part . In order to solve this problem, we are judging 3D Before responding, it is necessary to judge whether the finger clicks on UI On . before NGUI It's all about yourself ...

2. Nginx Reverse agent and load balancing —— Personal configuration

#user nobody; worker_processes 2; #error_log logs/error.log; #error_log logs/error.log notice; #erro ...

3. DetailsView The addition of , modify , Delete , Inquire about

The front desk code : <div> <asp:DetailsView ID="gvDepart" runat="server" AutoGenerateR ...

4. Appium + Python ------------- Element localization

Said in the previous 1.https://github.com/appium/python-client/tree/master/test   There's some in there test , You can see , The research study 2. Learn how to use uiautom ...

5. Decode an encrypted js file

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

6. unittest Common methods of modules ：

unittest Common methods of modules : assertEqual(a, b)     a == b assertNotEqual(a, b)     a != b assertTrue(x)     bool ...

7. luogu4643 [ National Team ] Ali and peach game

Topic link : Luogu This problem is very difficult at first sight , And the label on the title is scary . But in fact, this problem is not difficult to write ( Just think about it ...emm) Because we just need to know the difference between the two scores , So we can transform the conditions . We divide the border power equally into ...

8. list set map Differences and applicable scenarios

list And Set.Map Differences and applicable scenarios   1.List,Set It's all inherited Collection Interface ,Map It is not 2.List characteristic : Element has put order , Element repeatable ,Set characteristic : Element has no placement order , The element cannot be repeated ...

9. Docker swarm actual combat - Deploy wordpress

Docker swarm actual combat - Deploy wordpress Create a overlay Network of docker network create -d overlay demo 6imq8da3vcwvj2n499k ...

10. Android When sharing to wechat, click share to solve the problem of no response （ matters needing attention ）

Problem description : Call sharing to wechat sdk Click the share button of the program, and the program doesn't respond terms of settlement : Question why : Wechat sharing has very strict requirements for clients , First of all, you have to register an account for the app , Fill in the registration information relatively completely , among “ App package name ”,“ The signature of the application ...