C Program to find the Factorial of Given Number
/** C Program to find the Factorial of Given Number **/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <stdio.h> //#include<conio.h> int main() { int num,i,fact=1; //clrscr(); printf("\n >> PROGRAM TO FIND FACTORIAL OF GIVEN NUMBER <<\n"); printf("\n Enter the Number whose Factorial you want: "); scanf("%d",&num); for(i=num; i>=2 ; i--) //i is intializing with num value and is decremented till 2 { fact = fact * i; //fact is updating with changing value of i } printf("\n The factorial of %d is %d.\n\n",num,fact); //getch(); return 0; //indicate end of program to OS } |
Sample Output:
( using GNU GCC Compiler with code::blocks IDE, hence no need of clrscr(); and getch(); )
For C# Program : C# Program to Find Factorial of Number