0
What's wrong with this code?
I had a task: The calendar of inhabitants of planet Pljuk consists of N months, every month consists exactly of 30 days, week consists of 7 days. Particularly unlucky on the planet Plyuk is the 13th month, if it falls on Friday. It is known that the New Year on the planet Plyuk started on the k-th day of the week (1st day of the week - Monday, 2nd - Tuesday, 3rd - Wednesday, ..., 7th - Sunday). Determine how many this year on the planet Plyuk will be especially unhappy Fridays, the 13th. Input: k - New Year's day of the week, N - how many months in a year https://code.sololearn.com/cSJgn2uJxFyj/?ref=app
2 Answers
+ 2
Your code:
if(N!=0)
{
statement;
return ();
}
so when N is equal to 0, it is not return anything and the solution(delete the cout statement in main, just friday13(counter,k,N)
int friday13 (int &counter, short int &k,long int N){
if (N==0)
{cout<<counter;
return 0;}
else {
for (int i=0;i<30;i++){
if ((i+1==13)&&(k==5)){counter++;}
if (k<7){k++;}
else {k=1;}
}
return counter+friday13(counter, k, N-1);
0
Thank you!