So far i got this. But i am getting this error :
“Undefined references to `WinMain@16′ ”
Please help.
int sumEvensRecursively(int no1, int no2)
{
no1=5;
no2=20;
if (no1 % 2 == 1)
{
return sumEvensRecursively(no1+ 1, no2);
}
return no1+ sumEvensRecursively(no1+ 2, no2);
}
There are several issues wrong:
the function is recursive on all control paths, you need a stop condition.
it appears you pass
no1andno2as parameters, yet you assign them values on the next lines. What’s the point?the error you’re getting is because you’re probably compiling on windows, where the
main()is declared something likeint _tmain(int argc, _TCHAR* argv[])and notint main(int argc, char* args[]).tl;dr-
Conclusion:
Change the
mainmethod in your program toint wmainorint _tmainto solve the compiler error.Change the algorithm to get it to actually work.