Factorial of a Number In C Using Function

In this article, we are going to write a program to find Factorial of a Number In C Using Function.

To make this program, we will use the following concept given below.

If you do not know about these topics well, then you may not understand this program, so you should know about them in detail from the link given above.

Now without wasting time let’s start programming.

Factorial of a Number In C Using Function

Factorial of a Number In C Using Function

Algorithm

  • Program Start
  • Declaring Variable
  • Input Number From the user
  • Calling Function
  • Loop start
  • return result
  • function End
  • Display Result Through Printf Function
  • Program End

Program

//C program to find Factorial of a Number Using Function

#include<stdio.h>
int factorial(int num)
{  int i = 1, fact = 1;
   do
  {
      fact=fact*i;
      i++;
  } while(i<=num);

  return (fact);
}

void main()
{
  int n;

  printf("Enter a number: ");
  scanf("%d",&n);

  printf("Factorial of %d is: %d",n,factorial(n));

}

Output

Enter a number: 7
Factorial of 7 is: 5040

Conclusion

So friends, in this article, we have written a program to find Factorial of a Number In C Using Function.

If you have difficulty to understand any program or have any doubts or questions, then tell me in the comment below.

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming, and Blogging

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.