- #1
tawi
- 33
- 0
Homework Statement
I have a question about sequences in Pascal. I have been wondering if there is a way to write more than one element of succession on the output at once, without using arrays or strings. I guess best to illustrate on an example.
Let's take a program that should determine whether some number is a palindrome.
The code should look something like this:
Code:
...
begin
readln (number);
copy := number;
modifier := 0;
while number > 0 do
begin
modulo := number mod 10;
number := number div 10;
modifier := (modulo + modifier*10);
end;
if copy = modifier then
writeln (copy);
end.
But what if we know wanted to take a whole sequence of numbers and, at the end, write all the ones that were palindromes? Again without any usage of arrays or strings.
We would need to modify the code, the readln (number) would be at the end of the while cycle so after every number it would ask for a new one.
Writing 0 would end the cycle. That is pretty clear but how about the output?
How can we make the program remmember all the palindromes and not lose them during the cycle?
Thanks
Homework Equations
The Attempt at a Solution
Last edited: