Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2c449e0

Browse files
Merge pull request fnplus#655 from annu12340/master
Created new files (factorial, armstrong-number, recursion/palindrome)
2 parents 4e580b2 + e7d71c6 commit 2c449e0

File tree

7 files changed

+142
-0
lines changed

7 files changed

+142
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int i,fact=1,number;
6+
cout<<"Enter any Number: ";
7+
cin>>number;
8+
9+
for(i=1;i<=number;i++){
10+
fact=fact*i;
11+
}
12+
13+
cout<<"Factorial of " <<number<<" is: "<<fact<<endl;
14+
return 0;
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
num = int(input("Enter a number: "))
2+
3+
factorial = 1
4+
5+
# check if the number is negative, positive or zero
6+
if num < 0:
7+
print("Sorry, factorial does not exist for negative numbers")
8+
elif num == 0:
9+
print("The factorial of 0 is 1")
10+
else:
11+
for i in range(1,num + 1):
12+
factorial = factorial*i
13+
print("The factorial of",num,"is",factorial)
14+
15+
"""
16+
Or you can directly use the math.factorial() in python
17+
18+
import math
19+
num = int(input("Enter a number: "))
20+
print ("The factorial is ",math.factorial(num), end="")
21+
"""
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Armstrong number
2+
- Armstrong number is a number that is equal to the sum of cubes of its digits.
3+
4+
Example: 0, 1, 153, 370, 371 , 407
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
7+
int n,r,sum=0,temp;
8+
cout<<"Enter the Number= ";
9+
cin>>n;
10+
temp=n;
11+
12+
while(n>0)
13+
{
14+
r=n%10;
15+
sum=sum+(r*r*r);
16+
n=n/10;
17+
}
18+
19+
if(temp==sum)
20+
cout<<"Armstrong Number."<<endl;
21+
else
22+
cout<<"Not Armstrong Number."<<endl;
23+
24+
return 0;
25+
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
5+
int rev(int n, int temp)
6+
{
7+
8+
if (n == 0)
9+
return temp;
10+
11+
// stores the reverse of a number
12+
temp = (temp * 10) + (n % 10);
13+
return rev(n / 10, temp);
14+
}
15+
16+
17+
int main()
18+
{
19+
20+
cout<<"Enter the Number= ";
21+
cin>>n;
22+
int temp = rev(n, 0);
23+
if (temp == n)
24+
cout << "yes" << endl;
25+
else
26+
cout << "no" << endl;
27+
return 0;
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.io.*;
2+
3+
class Palindrome
4+
{
5+
6+
static int rev(int n, int temp)
7+
{
8+
if (n == 0)
9+
return temp;
10+
11+
// stores the reverse of a number
12+
temp = (temp * 10) + (n % 10);
13+
return rev(n / 10, temp);
14+
}
15+
16+
17+
public static void main (String[] args)
18+
{
19+
int n = 101;
20+
int temp = rev(n, 0);
21+
22+
if (temp == n)
23+
System.out.println("yes");
24+
else
25+
System.out.println("no" );
26+
}
27+
28+
29+
}
30+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def rev(n, temp):
2+
if (n == 0):
3+
return temp;
4+
5+
# stores the reverse of a number
6+
temp = (temp * 10) + (n % 10);
7+
8+
return rev(n / 10, temp);
9+
10+
11+
12+
n = int(input("enter a number : "));
13+
temp = rev(n, 0);
14+
if (temp != n):
15+
print("yes");
16+
else:
17+
print("no");
18+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /