Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,845 questions

51,766 answers

573 users

How to rotate array elements left N times in Pascal

1 Answer

0 votes
program RotateArray;

const
  N = 7;

var
  arr: array[1..N] of Integer;
  i, temp1, temp2: Integer;

procedure PrintArray;
begin
  for i := 1 to N do
    Write(arr[i], ' ');
  Writeln;
end;

begin
  // Initialize array 
  arr[1] := 1;
  arr[2] := 2;
  arr[3] := 3;
  arr[4] := 4;
  arr[5] := 5;
  arr[6] := 6;
  arr[7] := 7;

  // Print original array 
  PrintArray;

  // Rotate left by 2 positions 
  temp1 := arr[1];
  temp2 := arr[2];
  for i := 1 to N - 2 do
    arr[i] := arr[i + 2];
  arr[N - 1] := temp1;
  arr[N] := temp2;

  // Print rotated array 
  PrintArray;
end.



(*
run:

1 2 3 4 5 6 7 
3 4 5 6 7 1 2 

*)


 



answered Oct 22, 2025 by avibootz
edited Oct 22, 2025 by avibootz
...