Home > Back-end >  One small cows, since it was born 4 years, gave birth to a small cows per year, assuming that the bu
One small cows, since it was born 4 years, gave birth to a small cows per year, assuming that the bu

Time:09-26

How can get it to output the result right? Now the output is 0
 # include & lt; stdio.h> 
# include & lt; Math. H>
Int main () {
Int year=1;//number
Int num=1;//cow number
Int count=0;//counter
Do {
If (year % 4==0) {
count++;
Printf (" % d \ n ", pow (2, count));
} else {
Printf (" % d \ n ", pow (2, count));
}
Year++;//is there any need to write in this statement, while the condition is true through year++ at the bottom of the cycle time will exit the loop to walk?
} while (year>=4 & amp; & Year<=20);
Year++;
}

CodePudding user response:

While conditions, year is greater than or equal to 4 excessive, start conditions are not set up out of the,

CodePudding user response:

reference 1/f, arfi response:
no, while conditions year greater than or equal to 4 excessive, starting conditions was pulled out,

Emmm or not

CodePudding user response:

Algorithm is also wrong, 4 years began, not one every four years,
Born in the year of the 4 heifer 7 years again...

I always feel that the results have to add at least one bull!!!!!!

CodePudding user response:

reference arfi reply: 3/f
algorithm is also wrong, is 4 years began, not one every four years,
Born in the year of the 4 heifer 7 years again...

I always feel that the results have to add at least one bull!!!!!!

Oh oh is the algorithm content of I also not ha ha ha this bull subject didn't say

CodePudding user response:

This topic is quite round, want to half a day,
You have to use an array to record four years in a row the number of cattle,

F (1)=f (2)=f (3)=1;//1/2/3 said how many years these parameters, f/f (1) (2)/f (3) year of corresponding to the number of cattle
(4)=f (f3) + f (1);//4 years the number of cattle cattle is equal to the number of the previous year in the fourth year the number of mature cow + (that is, three years ago, the number of cattle)
(5)=f (f4) + f (2);
.
F (20)=f (19) + f (17);

CodePudding user response:

reference 5 floor arfi reply:
this topic is quite round, want to half a day,
You have to use an array to record four years in a row the number of cattle,

F (1)=f (2)=f (3)=1;//1/2/3 said how many years these parameters, f/f (1) (2)/f (3) year of corresponding to the number of cattle
(4)=f (f3) + f (1);//4 years the number of cattle cattle is equal to the number of the previous year in the fourth year the number of mature cow + (that is, three years ago, the number of cattle)
(5)=f (f4) + f (2);
.
F (20)=f (19) + f (17);

I write out how to make the circulation of recursive algorithm?
 # include & lt; stdio.h> 
Int main () {
Int year;//number
Int num=1;//cow number
int count;//counter
For (year=1; Year<=20; Year++) {
The count=(year/4);
Num=num + count;
Printf (" % d \ n ", num);
}
}

CodePudding user response:

Can not recursive don't recursion, performance is bad, enterprise products are generally not to use, easy to a problem, you need to use an array to record the number of cattle in the recent 3 years, loop it came out,

Recursion is for lazy people, refer to the following:
Int f (int year)
{
If (year & lt; 4)
return 1;

Return f (year 1) + f (year - 3)
}

It's a bit like junior high school learned equation, just won't be the problem using the method of primary school,

CodePudding user response:

Can not recursive don't recursion, performance is bad, enterprise products are generally not to use, easy to a problem, you need to use an array to record the number of cattle in the recent 3 years, loop it came out,

Recursion is for lazy people, refer to the following:
Int f (int year)
{
If (year & lt; 4)
return 1;

Return f (year 1) + f (year - 3)
}

It's a bit like junior high school learned equation, just won't be the problem using the method of primary school,

CodePudding user response:

refer to the eighth floor arfi response:
can not recursive don't recursion, performance is bad, enterprise products are generally not to use, easy to a problem, you need to use an array to record the number of cattle in the recent 3 years, loop it came out,

Recursion is for lazy people, refer to the following:
Int f (int year)
{
If (year & lt; 4)
return 1;

Return f (year 1) + f (year - 3)
}

It's a bit like junior high school learned equation, won't be a problem using the method of primary school,
ha ha ha ok this is not to cope with the homework? Thanks
  • Related