paulbradley
Programmer
If i have a variable holding the number 1234 say, is there a way of breaking this down and holding each digit in a different variable? The same goes for strings.
Thanks.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
program divide_up;
uses crt;
var
main, counter : integer;
separate : array[1..20] of integer;
procedure devide(i : integer);
var count : integer;
begin
for count := 1 to 20 do begin
separate[count] := i mod 10; {takes the last integer}
i := i div 10; {takes off the last integer}
end;
end;
begin
writeln('Enter in a number.');
readln(main);
devide(main);
writeln(main,' separates into : ');
for counter := 1 to 20 do writeln(separate[counter]);
readln;
end.