/** C Program to find the Factorial of Given Number **/
#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(); )
No comments:
Post a Comment
Thanks for your comments.
-Sameer