Recursion.

 RECURSION =  a function which call itself during its execution.

examples based on recurs on :

1.

Program to find the sum of the digits of the number. 

#include<stdio.h>
#include<math.h>
int sum(int);
int main()
{
    int i,k,n;
    printf("enter number = ") ;
    scanf("%d",&n);
    i=sum(n);
    printf(" \nsum of digit %d =%d",n,i);
    return 0;
}
int sum(int x)
{
    if(x==0)
    {
        return(0) ;
    }
    else
    {
        return(x%10+sum(x/10)) ;
    }
}

OUTPUT :

enter number = 57

sum of digit 57 =12

2.



Comments