Computer Science, asked by NISHAThameeda2614, 1 year ago

Find out the errors in the following :
int sum (int n)
{ if (n = = 0)
return 0;
else
return n +sum (n); }

Answers

Answered by Naresh5551
0
"==" is used for char only(for comparisons ).. so here it will be single = sign
Answered by adventureisland
0

Error in the given code snippet:

  • In the sum function, the return statement returns the sum of parameter passed with a recursive call to the function.
  • As the function sum does not have any provision for decrementing the value, it becomes an endless process of recursion and no meaningful value is returned.
  • We can use any loop so that the value of n can be incremented or decremented to make the code snippet error free

Similar questions