int sum(n)
{
if (n==0)
return 0;
else
return n+sum(n-1);
}
Chat with our AI personalities
program to find maximum of two numbers using pointers
#include<
using max function
In computer programming, both iteration and recursion define a type of loop. With iteration, the loop makes use of the current instance of the function in which it appears. When we start a new iteration, the "state" of the previous iteration is carried forward to the new iteration but we cannot return to a previous state. With recursion we can return to a previous state because each recursion invokes a new instance of the function which automatically saves the state of the current instance. Whenever we return from an instance, the result of that instance can be passed back to the previous instance and be incorporated into its restored state.To demonstrate, consider the following iterative loop (in C++):for (unsigned i=0; i
give an example of calculation of mathematics