Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions snippets/c/mathematical-functions/swap-numbers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Swap numbers
description: Swaps two numbers without using third variable
author: Emosans
tags: swap,numbers
---

```c
#include<stdio.h>
void swap(int* num1,int* num2){
*num1= *num1 + *num2;
*num2= *num1 - *num2;
*num1= *num1 - *num2;
}

// Usage:
int a=3,b=4;
auto swapped=swap(&a,&b); // simply use printf after this to print swapped values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto is a C++ keyword.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on it

```