1.11M Members

This doesn't make sense

 
0
 

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.
 
0
 

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

 
0
 

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

 
0
 

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

Question Answered as of 1 Year Ago by pritaeas and ddanbe
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article