Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+13 votes

include <stdio.h>

int main()
{

int i, n, t1 = 0, t2 = 1, nextTerm;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 1; i <= n; ++i)
{
    printf("%d, ", t1);
    nextTerm = t1 + t2;
    t1 = t2;
    t2 = nextTerm;
}
return 0;

}

asked in CSC350 by (1 point)

1 Answer

+9 votes

This could be solved by making t1, t2, and nextTerm a long or an unsigned integer. The reason is that a long and unsigned integer have more bits to represent larger positive numbers than an integer in the computer architecture. Although this was done last week, there would need to be changes to the printf for the format specifier as well as the integer to a long or unsigned integer.

answered by (1 point)
...