Thursday

Write a program to calculate the factorial of a given number using function.

#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
 int n,a;
 clrscr();
 printf("\nEnter any number: ");
 scanf("%d",&n);
 a=fact(n);
 printf("\n factorial= %d",a);
 getch();
 }

int fact(int n)
{
 int i,f=1;
 for(i=1;i<=n;i++)
 f=f*i;
 return f;
}

No comments:

Post a Comment

Rahul-Notes