How to FIND factorial IN C Program

This is a simple C++ program for beginners to find the factorial of a number. The recursive function is used to find the factorial of a number. 


Source Code

#include<stdio.h>
int fact(int n);
int main()
{
  int number,ans;
  printf("\n \n *************** FIND FACTORIAL ************** \n\n\n");
  printf("Enter Number : ");
  scanf("%d",&number);
  ans=fact(number);
  printf("\n Factorial : %d \n \n",ans);
return 0;
}
  
int fact(int n)
{
  int f;
  if(n==1)
  return (1);
  else
  f=n*fact(n-1);
return (f);
}

Output of the Program


C++ Programming

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment