0

How to prevent integer overflows in my fibonacci program

when i try to generate 100 terms of the fibonacci sequence it breaks down and gives me negative numbers indicating an overflow. using long int and long long int is of no use. can someone help me fix it> https://code.sololearn.com/c2wJt45BgkYe/?ref=app

30th Jun 2020, 12:53 PM
Saraswathi Reddy
Saraswathi Reddy - avatar
6 Answers
0
Create a class that stimulates big numbers.
30th Jun 2020, 12:56 PM
RinasSam
RinasSam - avatar
0
I'm still a beginner i dunno what classes are.
30th Jun 2020, 12:58 PM
Saraswathi Reddy
Saraswathi Reddy - avatar
0
don't worry i fixed it by changing the long int to unsigned long long int
30th Jun 2020, 1:04 PM
Saraswathi Reddy
Saraswathi Reddy - avatar
0
Try using long double.
30th Jun 2020, 1:04 PM
RinasSam
RinasSam - avatar
0
thanks but i fixed it.
30th Jun 2020, 1:05 PM
Saraswathi Reddy
Saraswathi Reddy - avatar
0
Use __uint128_t It can store integers btw 0 and 2^128-1
30th Jun 2020, 6:54 PM
Anthony Maina
Anthony Maina - avatar