Program swap two variables a,b
Delphi & Pascal (česká wiki)
Category: Source in Pascal
Program: Sswap.pas
Program: Sswap.pas
Program swap two variables a,b. Speciality is that program no needed third variable or stack. Unfortunately I'm not author of this.
{ SSWAP.PAS } { Program prehodi medzi sebou cisla a,b. } { Specialitou je ze nepotrebuje pomocnu premenu ani zasobnik. } { } { Datum:07.06.2006 http://www.trsek.com } program superswap; var a,b: integer; begin { precita cisla } writeln('Program vymeni 2 cisla medzi sebou bez pomocnej premenej'); write('Zadaj a = '); readln(a); write('Zadaj b = '); readln(b); { zacnu kuzla } a:=b-a; b:=b-a; a:=b+a; { vypise cisla } writeln('Vymenene cisla su'); writeln(' a = ',a); writeln(' b = ',b); readln; end.