-
Notifications
You must be signed in to change notification settings - Fork 0
/
All_numbers.cpp
175 lines (163 loc) · 3.27 KB
/
All_numbers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
class AllNumbers{
public:
int n;
void table()
{
cout<<"Enter number for multiplication table=";
cin>>n;
for(int i=1;i<=10;i++)
{
cout<<n<<"X"<<i<<"="<<n*i<<endl;
}
}
void factorial()
{
cout<<"Enter number for factorial=";
cin>>n;
int fact=1;
for(int i=n;i>=1;i--)
{
fact=fact*i;
cout<<i<<" ";
}
cout<<"="<<fact<<endl;
}
void prime()
{
cout<<"Enter number to check prime=";
cin>>n;
int counting=0;
for(int i=2;i<n;i++)
{
if(n%i==0)
{
counting++;
break;
}
else{
continue;
}
}
if(counting==0)
{
cout<<n<<" is prime"<<endl;
}
else{
cout<<n<<" is not prime"<<endl;
}
}
void gcd_lcm()
{
int n1,n2,r,num1,num2,lcm,gcd;
cin>>num1;
cin>>num2;
if(num1<num2)
{
n1=num1;
n2=num2;
}
else{
n2=num1;
n1=num2;
}
while(n1!=0)
{
r=n2%n1;
n2=n1;
n1=r;
}
gcd=n2;
cout<<"GCD= "<<gcd<<endl;
lcm=(num1*num2)/gcd;
cout<<"LCM= "<<lcm<<endl;
}
void sumOfDigit()
{
int sum=0,result,remainder;
cout<<"enter the number= ";
cin>>n;
int number=n;
while(number!=0)
{
result=number/10;
remainder=number%10;
sum=sum+remainder;
number=result;
}
cout<<"sum of digits= "<<sum<<endl;
}
void reverseDigit()
{
int sum=0,result,remainder;
cout<<"enter the number= ";
cin>>n;
int number=n;
while(number!=0)
{
result=number/10;
remainder=number%10;
sum=sum*10+remainder;
number=result;
}
cout<<"reverse of the number= "<<sum<<endl;
}
void palindrome()
{
int sum=0,result,remainder;
cout<<"enter the number= ";
cin>>n;
int number=n;
while(number!=0)
{
result=number/10;
remainder=number%10;
sum=sum*10+remainder;
number=result;
}
if( n == sum )
{
cout<<"Number is palindrome"<<endl;
}
else{
cout<<"Number is not palindrome"<<endl;
}
}
void armstrong()
{
int sum=0,result,remainder;
cout<<"enter the number= ";
cin>>n;
int number=n;
while(number!=0)
{
result=number/10;
remainder=number%10;
sum=sum+remainder*remainder*remainder;
number=result;
}
if(sum==n)
{
cout<<"Armstrong number"<<endl;
}
else{
cout<<"Not armstrong number"<<endl;
}
}
};
int main()
{
AllNumbers s;
s.table();
s.factorial();
s.prime();
s.gcd_lcm();
s.sumOfDigit();
s.reverseDigit();
s.palindrome();
s.armstrong();
getch();
}