Write a c program to find the factorial of a number using function
#include<stdio.h>
#include<conio.h>
void main()
{
int factorial(int);
int n,fact;
clrscr();
printf("Enter the number: ");
scanf("%d",&n);
fact=factorial(n);
printf("%d!=%d",n,fact);
getch();
}
int factorial(int n)
{
int f=1,i;
for(i=1;i<=n;i++)
f=f*i;
return(f);
}
Output:
Enter the number: 3
No comments: