Code Review
All return paths from a function must return value. Leaving a function that has a non void type without a return is undefined behavior (google nasal dragons).
int getZeroes(long long n){
if(n>0){
// STUFF
return stuff;
}
// BUT HERE there is no return.
// Any negative value or zero causes undefined behavior.
}
This while loop seems overly cumbersome with a break;
while(a%5){
if(a%5 == 0){ // will this ever be true.
// STUFF // Since it is just after a test that checks the opposite?
}else{
break;
}
a = a/5;
}
This looks exactly the same both sides of the else:
return (b+getZeroes(n-1));
}else{
return (getZeroes(n-1));
The only difference is b (which just needs to be made zero for the second case then) you can yank it out of the conditional.
Why store the results?
x.push_back(getZeroes(cases));
The only thing you do with them is print them. May as well just print them as you generate them!
- 97.7k
- 5
- 126
- 341