Fortune Telling Collection - Free divination - C language programming If a heifer gives birth to a cow every year from the fourth year, according to this rule, how many cows will there be in the nth year?
C language programming If a heifer gives birth to a cow every year from the fourth year, according to this rule, how many cows will there be in the nth year?
//VS2005 debugging passed!
# include & ltiostream & gt
Use namespace std
int main()
{
int I;
int n; //year
Int num// number of cattle
//type[0] represents a newborn cow, type[ 1] represents a cow in the second year after birth, type[2] represents a cow in the third year after birth, and type[3] represents a cow that has started production.
int type[4]={ 1,0,0,0 };
Cout & lt& lt "Enter number of years:";
CIN & gt; & gtn;
for(I = 1; I & ltn;; i++)
{
Type [3] += Type [2];
type[2]= type[ 1];
type[ 1]= type[0];
Type [0] = Type [3];
}
num = type[0]+type[ 1]+type[2]+type[3];
Cout & lt& lt The total number of cows is: < & ltnum & lt& ltendl.
Returns 0;
}
- Previous article:How to start divination in Zhouyi
- Next article:Are dogs similar to snakes? Are dogs similar to snakes?
- Related articles
- How to judge your horoscope according to your birthday?
- Give an English fairy tale script
- Analysis on the steps and skills of pet epiphany in mobile games.
- Ask for a useless classic quotation of the silver soul?
- At the end of Sui Dynasty, the characters got high marks.
- Excuse me, where is this painting?
- Analysis on the skills of dragon ball jumping cross to attract soldiers to be curious
- Will the turtle shell explode when heated locally?
- It is essential to have a creative and pleasant app company name and a complete collection of industry vocabulary.
- Clannad detailed story