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

About This Blog

This blog will contain c programs related to interview preparation, basic programs, operating system, graphics, data structure, algorithms implementation, compiler and porjects. C is one of the most widely used programming languages of all time. This blog is intended for engineer students and for the people who are preparing for their interview in IT sector.

Share and Save