programming in general, not just C language, use of exercises related to the Fibonacci series is a classic, and in this exercise, the idea is to print the first n numbers series, where n is a predefined value and restrictions of language should not be a very large number.
We will print the first 20 numbers in Dev-C series.
# include \u0026lt;iostream>
using namespace std;
int previous1 , anterior2, current, i;
int main (void )
{court \u0026lt;\u0026lt;"This program will print the first 20 numbers in the series of Fibbonacci "\u0026lt;\u0026lt;endl;
system (" pause ");
previous1 = 0;
anterior2 = 1;
court \u0026lt;\u0026lt;previous1 \u0026lt;\u0026lt;endl;
court \u0026lt;\u0026lt;anterior2 \u0026lt;\u0026lt;endl ;
for (i = 1; i \u0026lt;= 20; i + +)
/ * The 20 refers to the amount of numbers to print * /
{+ current = anterior2 previous1, previous1 = anterior2
;
court \u0026lt;\u0026lt;today \u0026lt;\u0026lt;endl;
anterior2 = current;}
system ("pause");
return 0;
}
Also in this case, it is possible to modify the program so that the user enter the value of 'n', and it would be better instead to report the numbers as int, long double it as , embracing a greater number of digits when the numbers start to become very large, and would read:
previous1 long double, anterior2, current, i;
long double main (void )
0 comments:
Post a Comment