Skip to content

Commit 0c4355d

Browse files
authored
Add files via upload
1 parent a5ddd9d commit 0c4355d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

perfectnums.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
#include <iostream>
3+
#include <stdlib.h>
4+
using namespace std;
5+
//algorithm to check whether the given number is a perfect number(i.e. sum of factors of the number equal to the number itself)
6+
int main()
7+
{
8+
int n;
9+
int sum=0;
10+
cout<<"enter the number you wan tot check"<<endl;
11+
cin>>n;
12+
for (int i=0 ; i<n ; i++)
13+
{
14+
if (n%i==0)
15+
{sum+=i;}
16+
}
17+
if(sum == n)
18+
{cout<<"this number is a perfect number";}
19+
20+
else
21+
{cout<<"not a perfect number";}
22+
23+
return 0;
24+
}

0 commit comments

Comments
 (0)