Looking For Anything Specific?

ads header

Write a program to find the factorial of a number in C

 From this example, we will understand that how to find the factorial of any number using C Programming Language.


To understand this program, you should have knowledge of these C programming Topics :
  • Data Types in C
  • Do-while Loop in C

Write a program to find factorial of a number in C ?

 Program 

Using do-while Loop

#include<stdio.h>
#include<conio.h>
void main()
{
       int num,fact=1;
       clrscr();
       printf("\n Enter the no =");
       scanf("%d",&num);

       do
       {
               fact=fact*num;
               num=num-1;
       }
       while(num>=1);

       printf("\n Factorial = %d",fact);
       getch();
}

 Output 
Enter the no = 5
Factorial = 120


Post a Comment

0 Comments