Pages

Saturday, 20 April 2013

C code to find Factorial of given Number

//C code to find Factorial of given number. //

C program:

#include<stdio.h>
#include<conio.h>
long int factorial(int);

void main()
{
   
    long int fact;
    int n;
    clrscr();
    printf("Enter the number\n");
    scanf("%d",&n);
    fact=factorial(n);
    printf("\nThe factorial of %d is %ld ",n,fact);
    getch();
}
long int factorial(int n)
{
    long int fact=1;
    int i;
    for(i=1;i<=n;i++)
    {
        fact=fact*i;
    }
    return fact;
}

Output of the above Program:

Factorial-Result
Factorial Result

No comments:

Post a Comment

Back to Top