Exchange two elements of an array

FlamingClaw 0 Tallied Votes 958 Views Share

We change the order of elements of a vektor
Created by FlamingClaw

{Exchange two elements of an array}
Program exchange;
Uses Crt;
const min = 0;
      max = 3;
Var  Words:Array[min..max]of String[10];
     Helper:String[10];
     Index:Byte;

Begin{main}
     ClrScr;
     Words[0]:='Apple';
     Words[1]:='Peach';
     Words[2]:='Sun';
     Words[3]:='Wine';
     {write this results to the screen}
     For Index:=0 To max Do WriteLn(Index,'.',Words[Index]);
     WriteLn;
     {now,we exchange the 0. and the 2. elements}
     Helper:=Words[0];
     Words[0]:=Words[2];
     Words[2]:=Helper;
     {and then write changed results to the screen}
     For Index:=0 To max Do WriteLn(Index,'.',Words[Index]);
     ReadKey;
End.{main}

{Created by FlamingClaw 2009.03.10.}