Recursion Example

code:

#include<stdio.h>
void printMsg(unsigned int n)
{
    if(n==0)
        return; //when we are using return in void function it is outing from this loop as well as function and going back to its caller's return 0 that means ultimately in main() function
    printf("Hello World %d\n",n);
    n--;
    printMsg(n); //recursively calling printMsg

}
int main()
{
    printMsg(5); //call to printMsg function
    return 0;
}

 

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *