Skip to content

Commit 9433006

Browse files
committed
new snippet- swap numbers
1 parent 794eccd commit 9433006

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Swap numbers
3+
description: Swaps two numbers without using third variable
4+
author: Emosans
5+
tags: swap,numbers
6+
---
7+
8+
```cpp
9+
#include<tuple>
10+
std::tuple<int,int> swap(int num1,int num2){
11+
num1=num1+num2;
12+
num2=num1-num2;
13+
num1=num1-num2;
14+
return std::make_tuple(num1,num2);
15+
}
16+
17+
// Usage
18+
auto swapped=swap(3,4); // Returns a tuple (access the values using std::get<0>(swapped)/std::get<1>(swapped))
19+
```

snippets/cpp/string-manipulation/string-int.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)