C Program to find factorial of a number using functions.

/* Write a C Program to find factorial of a number using functions.  */
==================================================
#include<stdio.h>
#include<conio.h>
void main()
{
int a,f;
int fact(int);
clrscr();
printf(“enter a no: ”);
scanf(“%d”,&a);
f=fact(a);
printf(“factorial= %d”,f);
getch();
}
int fact(int x)
{
int fac=1,i;
for(i=x;i>=1;i--)
fac=fac*i;
return(fac);
}

Output:
======
enter a no: 5
factorial=120

No comments: