Code Box
------------------------------------------------------------
/*Program to print factorial of any input number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num,fact;
/* If we take fact as integer, it can not be able
to store factorial of value greater than 8 */
fact=1;
clrscr();
printf("\nEnter any number:");
scanf("%d",&num);
clrscr(); //for clear screen
printf("\n-------------------------------");
printf("\nNumber entered is: %d",num);
printf("\n-------------------------------");
printf("\n(When Fact as integer)\n");
printf("\nFactorial of %d is:",num);
printf("\n-----------------------------\n");
do
{
if(num==0)
{
printf("\n1"); //factorial of 0 is 1
break;
}
fact=fact*num;
num--;
}while(num>=1);
printf("\n%d",fact);
printf("\n------------------------------");
getch();
}
No comments:
Post a Comment