COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
perfect.cpp File Reference
#include <iostream>
Include dependency graph for perfect.cpp:

Go to the source code of this file.

Functions

bool isPerfect (int j)
 
int main ()
 

Variables

const int N = 1000
 

Function Documentation

◆ isPerfect()

bool isPerfect ( int j)

Definition at line 8 of file perfect.cpp.

8 {
9 int sum_factor = 0;
10 for (int factor = 1; factor<j; factor++){
11 if (j % factor == 0) {
12 sum_factor += factor;
13 }
14 }
15 return j == sum_factor;
16}

Referenced by main().

Here is the caller graph for this function:

◆ main()

int main ( void )

Definition at line 20 of file perfect.cpp.

21{
22 cout << "For the integers from 1 to " << N << ":\n";
23
24 for (int j = 2; j <= N; ++j)
25 if (isPerfect(j))
26 cout << j << " is perfect\n";
27
28 cout << endl;
29
30 return 0;
31}
bool isPerfect(int j)
Definition perfect.cpp:8
const int N
Definition perfect.cpp:18

References isPerfect(), and N.

Here is the call graph for this function:

Variable Documentation

◆ N

const int N = 1000

Definition at line 18 of file perfect.cpp.

Referenced by main().