Fibonacci Sequence Generator

0 Ray Haq · December 14, 2014

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
    int i, temp;
    int firstNumber = 1;
    int secondNumber = 1;
    printf("%i\n%i\n", firstNumber, secondNumber);

    for(i =0; i<100; i++){
        temp = secondNumber;
        secondNumber += firstNumber;
        firstNumber = temp;
        printf("%i\n", secondNumber);
    }
    return 0;
}

Something goes wrong when i run this program! some result comes with '-' sign! i dont know why...... can someone please explain this????

Post a Reply

Replies

Oldest  Newest  Rating
0 c student · December 14, 2014
i believe your int numbers aren't big enough to store such large values, making it "wrap" back around to its lowest negative value.  try using doubles.
+1 Ray Haq · December 14, 2014
Thank u!! i got the problem..... but i dont know about GMP at all....
can you help me with link or hints.....
if you can please!!
  • 1

C

103,721 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator