-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmStrongAndPerfectNumbersFunction.cpp
More file actions
63 lines (59 loc) · 1020 Bytes
/
armStrongAndPerfectNumbersFunction.cpp
File metadata and controls
63 lines (59 loc) · 1020 Bytes
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
#include <iostream>
using namespace std;
void armStrongNumber(){
int n,remainder,sum=0,temp;
cout<<"Enter number"<<endl;
cin>>n;
temp=n;
while(n>0)
{
remainder=n%10;
sum=sum+(remainder*remainder*remainder);
n=n/10;
}
if(temp==sum)
{
cout<<temp<<" is a Armstrong Number"<<endl;
}
else
{
cout<<temp<<" is not an Armstrong Number"<<endl;
}
}
void perfectNumbers(){
int n,sum=0,i;
cout<<"Enter number"<<endl;
cin>>n;
for(i=1;i<n;i++)
{
if(n%i == 0)
{
sum=sum+i;
}
}
if(n==sum)
{
cout<<n<<" is a Perfect Number"<<endl;
}
else
{
cout<<n<<" is not a Perfect Number"<<endl;
}
}
int main()
{
int x;
cout<<"Enter 1 to calculate perfectNumbers\nEnter 2 to calculate Armstrong numbers"<<endl;
cin>>x;
switch (x){
case 1:
perfectNumbers ();
break;
case 2:
armStrongNumber ();
break;
default:
cout<<"You entered wrong input"<<endl;
}
return 0;
}