Wednesday, July 20, 2011

Factorial of a number.

/*Serial No.16     [swami98.cpp]*/ 

/* this program can calculate factorial upto n=12 */
#include<stdio.h>
#include<conio.h>
int n;
main()
{
long int fact=1;
printf("Enter the no. whose factorial you want to calculate: ");
scanf("%d",&n);
if(n<0)
printf("You have entered Negative No. \nNumber can't be negative.\n");
if(n==0)
printf("Factorial of '0' is:\n");
while(n>0)
{
fact=fact*n;
n=n-1;
}
printf("Factorial= %ld\n",fact);
getch();
return(0);
}

No comments:

Post a Comment

If you have any doubt, feel free to ask...