Factorial of any number is the product of all the numbers below it till 1 for example
 factorial of 5 is 5*4*3*2*1 = 120 so this program will take the number as input
 from user and will give the factorial of a number as an output on screen.

Program 

#include<stdio.h>

#include<conio.h>

void main()

  int fac=1,n;

  printf("Enter the value of n:");

  scanf("%d",&n);  

do

  {

    fac=fac*n;

    n=n-1;

  } while(n>0);

    printf("factorial of given no is:%d",fac);

 }

 Output:

 

  

here, n=n-1 decrement operator is used to get numbers below the entered number and fac=fac*n will make product of them after every product value of fac is updated and stored in fac.


Post a Comment

Previous Post Next Post