C program to find factorial of a number
>> Wednesday, November 2, 2011
C program to calculate factorial of a number :
For an integer n greater than or equal to 1, the factorial is the product of all integers less than
or equal to n but greater than or equal to 1. The factorial value of 0 is defined as equal to 1.
The factorial values for negative integers are not defined.
For eg : factorial of 5 i.e 5!=5*4*3*2*1=120.
#include<stdio.h>
#include<conio.h>
int fact(int );
int main( )
{
int a, f ;
printf ( "\nEnter any number " ) ;
scanf ( "%d", &a ) ;
f = fact ( a ) ;
printf ( "Factorial value = %d", f ) ;
getch();
}
int fact ( int x )
{
int f = 1, i ;
for ( i = x ; i >= 1 ; i-- )
f = f * i ;
return ( f ) ;
}
Output :
C program to find factorial. |
0 comments:
Post a Comment