Logo

Programming-Idioms

Swap the values of the variables a and b
Implementation
Cobol

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Cobol implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
a, b = b, a
a, b = b, a
var tmp = a;
a = b;
b = tmp;
T tmp = a;
a = b;
b = tmp;
$tmp = $a;
$a = $b;
$b = $tmp;
a, b = b, a
($a, $b) = ($b, $a);
std::mem::swap(&mut a, &mut b);
a^=b;
b^=a;
a^=b;
auto temp = a;
a = b;
b = temp;
var tmp = a;
a = b;
b = tmp;
tmp := a;
a := b;
b := tmp;
swap (a,b) = (b,a)
{a, b} = {b, a}
fun1(A, B) ->
	do:something(),
	fun2(B, A).

fun2(A, B) ->
	now(A, is, B),
	and(B, is, A),
	keep:moving().
a, b = b, a
#include <utility>
using std::swap;
swap(a, b);
val tmp = a
a = b
b = tmp

var tmp = a;
a = b;
b = tmp;
[a, b] = [b, a];
import std.algorithm.mutation : swap;
swap(a,b);
(rotatef a b)
(a, b) = (b, a);
tmp = a
a = b
b = tmp
list($b, $a ) = [ $a, $b ];
Sub Swap(Of T)(ByRef a As T, ByRef b As T)
  Dim tmp as T
  tmp = a
  a = b
  b = tmp 
End Sub
procedure swap(a, b: in out Integer)
is
    temp : Integer;
begin
    temp := a;
    a := b;
    b := temp;
end swap;
a = b.also { b = a }
__typeof(a) _temp=a; a=b; b=_temp;
let (a, b) = (b, a);
(define (swap a b)
  (list b a))
(defn swap [a b]
  [b a])
subroutine swap(a, b)
  integer, intent(inout) :: a, b
  integer :: temp
  temp = a
  a = b
  b = temp
end subroutine swap
[| temp | temp := a. a := b. b := temp] value
[ $b, $a ] = [ $a, $b ];
swaps variables
a =int(input("enter a number"))
b =int(input("enter b number")) 
a, b = b, a
 
print("Value of a:", a)
print("Value of a", b)