Wednesday, April 22, 2020

Recursion using factorial in C


  • Flowchart :






  • Syntax :

void recursion() {
   recursion(); /* function calls itself */
}

int main() {
   recursion();
}
  • Program :

#include <stdio.h>
#include <conio.h>
int fact (int);
void main()
{
    int n,f;
    clrscr();
    printf("\n----------------RECURSION----------------");
    printf("Enter the number :");
    scanf("%d",&n);
    f = fact(n);
    printf("factorial = %d",f);
}
int fact(int n)
{
    if (n==0)
    {
        return 0;
    }
    else if ( n == 1)
    {
        return 1;
    }
    else 
    {
        return n*fact(n-1);
    }
    getch();
}



  • Output :





No comments:

Post a Comment

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...