0
Need help in this.
#include<iostream> #include<conio.h> using namespace std; int main() { int a = 6, sum = 0, n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0; int i = 1; while (i <= 5) { if (a%i == 0) { n1 = i; } else if (a%i == 0) { n2 = i; } else if (a%i == 0) { n3 = i; } else if (a%i == 0) { n4 = i; } else if (a%i == 0) { n5 = i; } else { cout << "Invalid" << endl; } i++; } sum = n1 + n2 + n3 + n4 + n5; cout << sum << " is perfect number" << endl; _getch(); return 0; }
1 Respuesta
+ 1
Determine a perfect number is much easier.
Look:
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int i = 1;
int sum = 0;
while (i < n) {
if (n % i == 0) {
sum = sum + i;
}
i++;
}
if (n == sum)
cout << n << " is perfect number." << endl;
else
cout << n << " is not perfect number." << endl;
}