Your question, your audience. Choose who sees your identity—and your question—with question security.

Hello

I need to write a program that receives a

real num. if the frac part of the num is a

mirror image of the whole part, (for example:

123.321 is, 52.9 isn't, 43.30 isn't, etc.) then

the program will print "yes" else it will print

"No". the point is that you don't know how many

digits the num has. Please tell me how to it

(without using external units or anything complex)

I need it urgently and ASAP!!!!!!!!!!!!!!!

Thanks

P.S. It's not homework, but a question I had last year.

I need it urgently because I have been trying for

months and I didn't manage to do it. So if you can

do it - please post your answer! Thanks!

I need to write a program that receives a

real num. if the frac part of the num is a

mirror image of the whole part, (for example:

123.321 is, 52.9 isn't, 43.30 isn't, etc.) then

the program will print "yes" else it will print

"No". the point is that you don't know how many

digits the num has. Please tell me how to it

(without using external units or anything complex)

I need it urgently and ASAP!!!!!!!!!!!!!!!

Thanks

P.S. It's not homework, but a question I had last year.

I need it urgently because I have been trying for

months and I didn't manage to do it. So if you can

do it - please post your answer! Thanks!

Here you'll have to take each number one by one and convert. Have fun. Also check to see if it is a full stop.

boolean result is set to true

The with a for loop

compare the first char to the last char

Are they equal - then keep going? If false set result to false

Increment the pointer to the first char and decrement the pointer to the last char. And go to the compare again.

var

i :integer;

number, f :real;

match, done :boolean;

.

.

.

i := trunc(number);

f := 10 * frac(number);

match := true;

done := false;

while (match and not done) do begin

if (i mod 10 <> trunc(f)) then

match := false

else begin

i := i div 10;

f := 10 * frac(f);

if (i = 0) then done := true

end;

end;

"number" should contain the number you want to test, and "match" will contain the result of the comparison.

Your solution is good but doesn't work

if the number has 1 in it for example 123.321

doesn't work. Any other number (for example:

349.943) does work. Why? Please try and fix.

Thanks

Const

Match: Boolean = False;

var

L,I,J: byte;

Tmp: String;

Begin

Write('Gimmy a number: ');

ReadLn(Tmp);

L:=Length(Tmp);

If Not((L Mod 2) = 0) And (L <> 1) Then

Begin

J:=L;

For I:=1 to ((L-1) Div 2) Do

If Tmp[I] = Tmp[J] Then

Match:=True

Else

Match:=False;

If Tmp[I+1] <> '.' Then

Match:=False

End;

If Match Then

WriteLn('Yes')

Else

WriteLn('No')

End.

the user input as a string that way it would be easy...>>

Very true. I must be getting old and decrepit.

Would pay for user to verify that valid input has been entered. Leave that as an exercise. :-)

The User can input something like A.A and the program will say yes... but this is homework...

var

i1,i2 :integer;

number :real;

match :boolean;

s :string[13];

begin

number := 13456.65431;

match := true;

str(number:13:6, s);

i1 := 6;

i2 := 8;

while (match and (i1 > 0)) do begin

if (s[i1] = ' ') then s[i1] := '0';

if s[i1] <> s[i2] then match := false;

dec(i1); inc(i2);

end;

writeln(match);

readln;

end.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

it checks for numbers too.

it also ignores the exponent (that e+06 in 123.45e+06), biased decimal points (1234.321), and signs that appears in the front, like -252

program try;

var i: integer;{loop control variable}

s: string;{user input}

e: integer;{required by val}

r: boolean;{reverse}

function checknum(s: string): boolean;

var f: boolean;{number flag}

p: boolean;{decimal point}

e: boolean;{exponent sign}

i: integer;{loop control variable}

begin

e := false;{initialization}

p := false;{initialization}

f := true;{initialization}

for i := 1 to length(s)do

begin

if f then

begin

if upcase(s[i]) = 'E' then

begin

if e then

f := false

else

e := true

end

else if (s[i]) = '.' then

begin

if (i > pos(s,'e')) and (i > pos(s,'E')) then

f := false

else

begin

if e then

f := false

else

e := true

end

end

else if (s[i] = '+') or(s[i] = '-') then

begin

if (i <> 1) and (i <> pos(s,'e')+1) and

(i <> pos(s,'E')+1) then

f := false

end

else if not (s[i] in ['0'..'9']) then

f := false

end

end;

checknum := f

end;

begin

writeln('I want a number here. ');

readln(s);{user input, set it to something else for defined inputs}

r := false;{initialization}

if checknum(s) then

begin

for i = 1 to length(s) do {drop exponents}

if not (s[i] in ['0'..'9','.','+','-'] then

del(s,i,length(s));

for i = length(s) downto 1 do

if (s[i] in ['0'..'9'] then

delete(s,i,1);

while s[1] = '0' do {delete leading zeros}

delete(s,1,1);

r = true;{check the thing now}

for i = 1 to (length(s) div 2) do

if s[i] <> s[length(s)-i] then

r := false;

end;

if r then

writeln('Yes')

else

writeln('No')

end.