File tree Expand file tree Collapse file tree 5 files changed +60
-1
lines changed Expand file tree Collapse file tree 5 files changed +60
-1
lines changed Original file line number Diff line number Diff line change 373735 . [ Shrey Aryan] ( https://github.com/shrey183 )
383836 [ Kautuk Kundan] ( https://github.com/kautukkundan )
393937 . [ Deepanshu Jain] ( https://github.com/thedeepanshujain )
40- 38 . [ Sanka Mohottala] (https://github.com/sankamohottala )
40+ 38 . [ Atieve Wadhwa] ( https://github.com/AtieveWadhwa )
41+ 39 . [ Sanka Mohottala] (https://github.com/sankamohottala )
42+ 40 . [ Your Name] ( https://github.com/yourusername )
Original file line number Diff line number Diff line change 1+ // program to find factorial of a given no. using recursive function.
2+
3+ #include < iostream.h>
4+ using namespace std ;
5+ int fac (int n){
6+ if
7+ {
8+ n<=1 return 1 ;
9+ }
10+ else
11+ {
12+ return n*fac (n-1 );
13+ }
14+ }
15+
16+ int main (){
17+ int i,n;
18+ cout<<" enter the no. for finding the factorial" ;
19+ cin>>n;
20+ i=fac (n);
21+ cout<<" the factorial of the given no. is " <<i;
22+ }
Original file line number Diff line number Diff line change 1+ //Atieve Wadhwa
2+ //Finding factorial of a number without recursion
3+ import java .util .*;
4+
5+ public class factorial
6+ {
7+ public static void main (String args [])
8+ {
9+ System .out .print ("Enter Number: " );
10+ Scanner s = new Scanner (System .in );
11+ int n = s .nextInt ();
12+ int ans = 1 ;
13+ while (n >1 )
14+ {
15+ ans = n *ans ;
16+ n = n -1 ;
17+ }
18+
19+ System .out .println ("The factorial is: " + ans );
20+ s .close ();
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ #Atieve Wadhwa
2+ #Finding factorial of a number without recursion
3+
4+ n = int (raw_input ("Enter number to find factorial of: " ))
5+
6+ ans = 1
7+
8+ while (n > 1 ):
9+ ans = ans * n
10+ n = n - 1
11+
12+ print ("Factorial of given number is:" )
13+ print (ans )
You can’t perform that action at this time.
0 commit comments