C program to find factorial of a number using non-recursive function
Today i am going to cover a simple program to find factorial of a number.To move further with program let quickly understand the factorial.
Factorial is nothing but multiplication of all the numbers that comes before that number.For example factorial of 5 is -
5*4*3*2*1 = 120.
Recursive function - If function calling itself,than this is a recursion.
We are using non-recursion method to find factorial of a number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> #include <conio.h> void main() { int n, a; clrscr(); printf( "Enter any number\n" ); scanf( "%d" , &n); a = Factorial(n); printf( "The factorial of a given number using recursion is %d \n" , a); getch(); } int Factorial( int x) { int i, f = 1; for (i = 1;i <= x; i++) { f = f * i; } return (f); } |
123Enter any number 5 The factorial of a given number using is 120Above program will take the input from user and calculate the factorial of it.
To calculate factorial of a number using recursion use below link -
http://www.codibucket.com/2016/08/c-program-to-find-factorial-of-number_28.html
Hope you like this post.Please provide your feedback.
Thanks.
C program to find factorial of a number using non-recursive function
Reviewed by CodiBucket
on
02:32
Rating:

No comments: