Skip to content

Commit fcac112

Browse files
authored
Merge pull request #410 from vanshaj7-hub/master
algorithm for finding perfect numbers
2 parents 2253270 + 80c973d commit fcac112

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

perfectnums.cpp

+24
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=1 ; 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)