0

Help to make a program that defines the perfect numbers in the one-dimensional array?

Transform it so that the imperfect numbers deduced the sum of their divisors. The source and the converted array of display

27th Feb 2017, 10:51 AM
Валерий ŠœŠ°Ń…ров
Валерий ŠœŠ°Ń…ров - avatar
1 Answer
+ 1
ŠžŃ€ŠøŠ³ŠøŠ½Š°Š»: #include <iostream> using namespace std; int main() { int a[] = {2, 3, 4, 5, 6, 28, 496}; for(int i = 0; i < sizeof a / sizeof *a; ++i) { int sum = 0; for(int j = 1; j <= a[i] / 2; ++j) sum += !(a[i] % j) * j; if(sum == a[i]) cout << a[i] << "\tis perfect number" << endl; } } Ремейк: #include <iostream> using namespace std; int main() { int a[] = {2, 3, 4, 5, 6, 28, 496}; for(int i = 0; i < sizeof a / sizeof *a; ++i) { int sum = 0; for(int j = 1; j <= a[i] / 2; ++j) sum += !(a[i] % j) * j; if(sum == a[i]) a[i] = 0; else a[i] = sum; cout << a[i] << ' '; } } ŠŸŃ€Š°Š²ŠøŠ»ŃŒŠ½Š¾ заГание ŠæŠ¾Š½ŃŠ»?
27th Feb 2017, 7:39 PM
SUPER_S
SUPER_S - avatar