COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
perfect.cpp
Go to the documentation of this file.
1
/*
2
This program prints out the perfect numbers between 1 and N
3
*/
4
5
#include <iostream>
6
using namespace
std;
7
8
bool
isPerfect
(
int
j){
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
}
17
18
const
int
N
= 1000;
19
20
int
main
()
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
}
isPerfect
bool isPerfect(int j)
Definition
perfect.cpp:8
N
const int N
Definition
perfect.cpp:18
main
int main()
Definition
perfect.cpp:20
Module5
perfect.cpp
Generated on Sun Sep 29 2024 16:39:53 for COMP2113 by
1.12.0