From 395900a264d285b0f628a428ec6eb601fc16b4ca Mon Sep 17 00:00:00 2001 From: Tisha Bhattacharya <73297135+Tisha1234@users.noreply.github.com> Date: Fri, 19 Feb 2021 02:06:03 +0530 Subject: [PATCH] program to find factorial of a given no. without using recursive function. program to find factorial of a given no. without using recursive function. --- math/C++/factorial.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/math/C++/factorial.cpp b/math/C++/factorial.cpp index 7215ee3..661c51b 100644 --- a/math/C++/factorial.cpp +++ b/math/C++/factorial.cpp @@ -1,21 +1,19 @@ -//program to find factorial of a given no. using recursive function. +//program to find factorial of a given no. without using recursive function. -#include +#include using namespace std; int fac(int n){ -if -{ - n<=1 return 1; -} -else -{ - return n*fac(n-1); -} + int m=1; + for(int j=1; j<=n; j++) + { + m=m*j; + } + return m; } int main(){ int i,n; -cout<<"enter the no. for finding the factorial"; +cout<<"enter the no. for finding the factorial : \n"; cin>>n; i=fac(n); cout<<"the factorial of the given no. is "<