Hi guys, so yeah, I got some IT homework AGAIN on programs and I repeatedly did trace tables and they all worked, but somehow, when I enter it in turbo pascal, after the 10th number, the digits start to get negative and after the 6th number, its not following the sequence... Anyways, the question states: Write a program to generate the first 20 terms of the following sequence: 1,3,3,9,27,243,6561.........here's the program that I did:

program sequence;

uses wincrt;

var X,Y,Result,i:integer;

Begin

 X:=1;
 Y:=3;
 Result:=X*Y;
 Writeln(X);
 Writeln(Y);
 For i:=1 to 18 do
 Begin
      Y:=X;
      X:=Result;
      Result:=X*Y;
      Writeln(Result);
 End;
End.

Recommended Answers

All 3 Replies

The digits get negative because the integer type cannot hold such large values.

In a way it makes sense!
An integer cannot hold numbers as big as 10^300 and higher, hence the negative values

ooooooooooooo Thanks guys... So i'll just tell the teacher that then!!! You guys deserve some reward lol :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.