Hello again, YOu guys have been such a big help in helping me understand what I'm doing wrong in my programs I'm hoping that I can get help again. I am currently writing a code in C. I'm supposed to be writing a code that has the Fibonacci Series up to 100 numbers, however when I run it it goes up to the 43 number, I believe, then starts going into the negitive. I tried exchanging the 'int' with 'long int' and that's not working either. MY code works great till the numbers get to big, is there a way that I can get the larger numbers to store as a varible?

You need to start by working out what data type you will use. Clearly the largest number you will have to deal with is [TEX]$F_{100}$[/TEX] which is 354224848179261915075, a fact you can verify with a simple web search.

What data types do you have available that might hold that number? Note that you will be wanting to use integer data types otherwise you will loose precision and not get the real numbers.

Being new to programming that question doesn't mean much to me. My first run was using {int i;} when the numbers came out to the negitive I tried {long int i;} both with %d and &i to scan and print my answers. My code compiles and runs, just don't know how to handel the large numbers.

Even 64-bit integer is not able to store such big numbers. You will need to store these numbers in array as sequence of digits and write your own addition operation of such big numbers, cause CPU can't add integers bigger than int-64 without loosing precision.

Like what 0x69 has said. You can use array of char to store large number and implement your own addition operation between two numbers. If you want to increase speed performance, you can use array of integer to store large number as well.

ok, I can understand the number being to big, and understand why I'm getting the negitive number. However I have no clue what you mean by array. F10 is 354224848179261915075 so do you mean having 35422484817 as one getch and 9261915075 as another.

The concept is very simple. Instead of storing number in Integer, you store number in array of char.

unsigned char num[40];

num[0] = '1';
num[1] = '3';
num[2] = '7';

Then you implement your own function to do addition between those two arrays of char.

However if you don't know about arrays then you may want to break off trying to solve this problem and learn about arrays first since they are a fairly basic feature of the C language that you will need to know in order to do anything terribly significant.

It appears that I'm going to have to do just that. Thanks guys for the tips I'm off to google arrays. Thanks again to those who assisted.

This article has been dead for over six months. Start a new discussion instead.