Skip to content

Commit 6cba2e9

Browse files
author
Bhrigu Kansra
authored
Merge pull request bhrigukansra#132 from AtieveWadhwa/master
Added factorial programs
2 parents fe688cb + 6f124c7 commit 6cba2e9

File tree

5 files changed

+60
-1
lines changed

5 files changed

+60
-1
lines changed

contributors.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@
3737
35. [Shrey Aryan](https://github.com/shrey183)
3838
36 [Kautuk Kundan](https://github.com/kautukkundan)
3939
37. [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)

math/C++/factorial.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

math/Java/factorial.class

928 Bytes
Binary file not shown.

math/Java/factorial.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

math/Python/factorial.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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)

0 commit comments

Comments
 (0)