C Program to find factorial of a number

Questions: Factorial Program in C. To find Factorial of a number using C Program. C program to find factorial of a given number. Factorial of a number in C. Program to find factorial using recursion.

Factorial of a number

Factorial of a number is represented by the symbol “!” and for any real positive number “n” it is written as “n!” where n! = 1 * 2 * 3 * …. * n. Here we will learn program for finding factorial of a number using C.

factorial-by-c

Required Knowledge and Software

 C Programming Operator
 C Programming Variable and C Programming expression
 C Programming Data Type
 C if statement
 C Programming for loop 
C Programming software Dev C++ /Turbo C++ 

Check: Flowchart for Factorial of a number

Logic to find factorial of a number in c programming 

Algorithm for finding factorial of a number with detailed explanation were discussed below:
  1. Input a number and store it in a variable say "num".
  2. Initialize another variable that will store factorial say "fact".
  3. Run loop from 1 to num.
  4. Multiply the current loop counter value.
Check: Area of triangle ; Flowchart for area of triangle

   Program to find factorial of a number


#include<stdio.h>
int find_factorial(int);
main()
{ 
int num, fact;
 //Ask user for the input and store it in num
 printf("\nEnter any integer number:");
 scanf("%d",&num);

 //Calling our user defined function
 fact =find_factorial(num);
   //Displaying factorial of input number
 printf("\nfactorial of %d is: %d",num, fact);
   return 0;
}
find_factorial(n)
{
 //Factorial of 0 is 1
   if(n==0)
  return(1);
 //Function calling itself: recursion
 return(n*find_factorial(n-1));
}

 Example

INPUT 
Enter any integer number: 5
OUTPUT
Factorial of 5 is : 120 

to-find-factorial-of-a-number-using-c-program

0 Comments