File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // main.cpp
3+ // perfectNumbers
4+ //
5+ // Created by samuel muloki on 12/05/2019.
6+ // Copyright © 2019 line23. All rights reserved.
7+ //
8+
9+ /* Note : According to Wikipedia : In number theory, a perfect number is a positive integer
10+ that is equal to the sum of its proper positive divisors, that is, the sum of its positive
11+ divisors excluding the number itself (also known as its aliquot sum). Equivalently, a
12+ perfect number is a number that is half the sum of all of its positive divisors (including
13+ itself).
14+ */
15+
16+ #include < iostream>
17+
18+ using namespace std ;
19+
20+ int main (int argc, const char * argv[]) {
21+ int num, i=1 , sum=0 ;
22+ cout <<" Enter a number: " ;
23+ cin >> num;
24+ while (i < num) {
25+ if (num % i == 0 )
26+ sum = sum + i;
27+ i++;
28+ }
29+ if (sum == num && sum != 0 ) {
30+ cout <<num<<" is a perfect number" ;
31+ } else
32+ cout <<num<<" is not a perfect number" ;;
33+ cout <<endl<<endl;
34+ return 0 ;
35+ }
Original file line number Diff line number Diff line change 1+ //
2+ // main.cpp
3+ // primeNumbers
4+ //
5+ // Created by samuel muloki on 12/05/2019.
6+ // Copyright © 2019 line23. All rights reserved.
7+ //
8+
9+ #include < iostream>
10+
11+ using namespace std ;
12+
13+ int main (int argc, const char * argv[]) {
14+ int i, num;
15+ cout <<" Enter any number: " ;
16+ cin >> num;
17+ if (num == 1 ) {
18+ cout <<" Smallest prime number is 2" ;
19+ }
20+ for (i = 2 ; i < num; i++) {
21+ if (num % i == 0 ) {
22+ cout <<num<<" is not a prime number" ;
23+ break ;
24+ }
25+ }
26+ if (num == i) {
27+ cout <<num<<" is a prime number" ;
28+ }
29+ cout <<endl<<endl;
30+ return 0 ;
31+ }
You can’t perform that action at this time.
0 commit comments