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 find the digit next to a given digit in a number with Pascal

1 Answer

0 votes
program DigitFinder;

uses
  SysUtils; // Format

function FindNextDigit(number, target: Longint): Longint;
var
  current, next: Integer;
begin
  next := -1;

  while number > 0 do
  begin
    current := number mod 10;
    number := number div 10;

    if current = target then
    begin
      FindNextDigit := next;
      Exit;
    end;

    next := current;
  end;

  FindNextDigit := -1;
end;

var
  number, target, result: Longint;

begin
  number := 8902741;
  target := 2;

  result := FindNextDigit(number, target);

  if result <> -1 then
    WriteLn(Format('The digit after %d in %d is %d.', [target, number, result]))
  else
    WriteLn(Format('The digit %d is not found or has no next digit in %d.', [target, number]));
end.



(*
run:

The digit after 2 in 8902741 is 7.

*)


 



answered Oct 18, 2025 by avibootz
...