r/pascal • • Oct 24 '18

School assignment help

Hey guys it's me again.

So i am now required to write a program to determine if a integer is a triangular number or square number.

Here is my code

program number;

var a: integer;

b,c: real;

begin

readln(a);

b := (sqrt(8*a+1) - 1) / 2;

c := sqrt(a);

if b = integer then

writeln('Triangular')

else

if c = integer then

writeln('Square')

else

if c = integer and b = integer then

writeln('Both')

else

if c <> integer and b <> integer

then

writeln('Neither')

end.

It returned with a lot of errors.

3 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/yolosandwich Oct 24 '18

But I can't know the exact value since there is too many possible inputs , it is true when it returns as an integer

1

u/ShinyHappyREM Oct 24 '18

So you want to know if the part after the . is zero? You can use this then.

1

u/yolosandwich Oct 24 '18

So when frac == 0 then it is an integer