Description
This program finds the factorial of a given number. The program does not use the concept of recursion. The value for n is read into the variable n. The program finds the factorial by multiplying each numbers form n to 1, each time decrementing the value for n.
Example
Factorial of 5
5*4*3*2*1=120
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=1,f;
clrscr();
printf("Enter the number");
scanf("%d",&n);
f=n;
i=n;
while(i>=1)
{
sum=sum*f;
i=i-1;
f=f-1;
}
printf("Factorial is %d",sum);
getch();
}
C program to find the factorial using recursion
No comments:
Post a Comment