0
1.6kviews
Write a recursive program to calculate factorial of accepted number.
1 Answer
1
43views

Algorithm:

Main () Function:

  • Start.
  • Enter a number to be printed.
  • Input a.
  • Fact = CALL factorial (arguments : a).
  • Print fact.
  • Stop

Factorial (parameters : a)

  • Start.
  • If a = 1, then return 1.
  • Else return (a*CALL factorial (arguments : a-1))
  • Stop.

Program:

#include <stdio.h>
#include <conio.h>

int main() {
    int no, factorial;
    int fact(int no);

    printf("Enter a Number:");
    scanf("%d", &no);

    factorial = fact(no);

    printf("Factorial = %d", factorial);
    getch();
}

int fact(int no){
    if(no==1)
    return 1;
    else
    return(no*fact(no-1));
}

Output:

Enter a Number: 5

Factorial = 120

Please log in to add an answer.