Blogger templates

Pages

Sunday, 6 May 2012

C Program: Find out the Factorial of a Number by using While Statement

factorial

Factorial :
  • Factorial of a non Negative number n is denoted by n!
  • Factorial Formula:  n! = 1*2*3*4.................*n
  •  Example:  5! = 5*4*3*2*1
Statement of C program: Input a number and compute its Factorial:

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c ;
clrscr();
printf("Enter the value of a\n ");
scanf("%d" ,&a);
b=1;
c=1;
while( b<=a )
{
c=c*b;
b++;
}
printf("Factorial=%d\n" , c)
getch();
}

Output1:
Enter the value of a
Factorial=120

Output2:
Enter the value of a
7
Factorial=5040



0 comments:

Post a Comment