//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:
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 |
No comments:
Post a Comment