Computer Science, asked by Jain1045, 1 year ago

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

Answers

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

Error in the program:

This program serves as an example for “recursive function”. Here, according to the value of ‘n’ the function gets repeated and the value of n gets added to the value returned by the function. There is no logical error found.

There is an error in the keyword “If”. In the word “if”, I is capital which is not allowed. If it is rectified, then no other error found in the program and the program runs smoothly.

Similar questions