Cow problem (original)

xiaoxiao2021-03-05  19

If a small cow begins with one cow from birth every four years, how many cows are in the nth year of this law. (Refer to C programming money)

Source: This is the first program that I have just written when I have a big two (2001). ^ _ ^.

(1): Texture within 20 years

#include

void main ()

{

Long Int A [20] [3];

INT I, J, N;

a [0] [0] = 1;

a [0] [1] = 1;

a [0] [2] = 1;

For (i = 1; i <20; i )

{

A [I] [1] = a [i-1] [0] a [i-1] [1] a [i-1] [2];

a [i] [0] = a [i] [1] -a [i-1] [1];

A [i] [2] = a [i] [1] a [i-1] [2];

}

CIN >> N;

IF (n% 3 == 0)

J = 2;

IF (n% 3 == 1)

J = 0;

IF (n% 3 == 2)

J = 1;

I = (N-1-J) / 3;

COUT << "" "" << "Year of the Year" << Endl;

COUT << a [i] [j] << endl;

}

(2) Recursive algorithm

#include

Long Int Cow (int);

void main ()

{

Int n;

Long Int Y;

COUT << "Input a integer number" << Endl;

CIN >> N;

Y = COW (n);

COUT << n << "" << Y << Endl;

}

Long int COW (INT N)

{

Long Int F;

IF (n <= 3)

Return 1;

Else

Return (COW (N-1) COW (N-3));

}

转载请注明原文地址:https://www.9cbs.com/read-38571.html

New Post(0)