Home > Back-end >  Questions about c language array
Questions about c language array

Time:11-17


C language of a one-dimensional array, each element assigned after what is respectively fixed does not change? If you can't change that why this f [I] in the program will be equal to f [I - 1) + f [2] I -? Is there a big woman,

#include
Int main ()
{
Int I, f [20]={1, 1};
for(i=2; i<20; I++)
[I] f=f [I - 2) + f [I - 1);
for(i=0; I<20; I++)
{if (I % 5=0) printf (" \ n ");
Printf (" % d ", f [I]); }
return 0; }

CodePudding user response:

In general, the array element can be changed after initialization, f=f [I] [I - 2) + f (I - 1), the meaning of this sentence is starting from the third element, at the back of each element is equal to the sum of the first two elements

CodePudding user response:

Not array elements you can modify the [I] f=f [I - 1) + f [2] I - is to start from the third element of an array of elements are the value of the first two elements and

CodePudding user response:

Calculate the Fibonacci sequence
1,1,2,3,5,...

CodePudding user response:

His address remains the same, that is, storage space, but not his storage contents cannot be changed,

CodePudding user response:

[I] said is address house number for I
F [I] is said that in the case of a house number I live a few people

CodePudding user response:

Advice to see the dynamic programming, you obviously have overlapping subproblems, the state transition equation, the array with no conflict,

CodePudding user response:

The
reference
if (I % 5=0) printf (" \ n ");
this is wrong, should be the if (I % 5==0)
  • Related