This C++ program finds and prints all perfect numbers between two integers entered by the user. It takes in two numbers as references, calls a function to get the range from the user, then calls another function that iterates from the starting to ending number, checks if each is a perfect number, and prints it out.
This C++ program finds and prints all perfect numbers between two integers entered by the user. It takes in two numbers as references, calls a function to get the range from the user, then calls another function that iterates from the starting to ending number, checks if each is a perfect number, and prints it out.
This C++ program finds and prints all perfect numbers between two integers entered by the user. It takes in two numbers as references, calls a function to get the range from the user, then calls another function that iterates from the starting to ending number, checks if each is a perfect number, and prints it out.
CMS ID: 244774 Synd: C OUTPUT #include<iostream> using namespace std; void start(int&, int&); void perfect(int, int); int main() { int a = 0, b = 0; start(a, b); cout << "perfect numbers between the range are :" << endl; if (a > 0 && b > 0) perfect(a, b); system("pause"); } void start(int & a, int & b) { cout << "Enter your starting number " << endl; cin >> a; cout << "Enter your last number" << endl; cin >> b; } void perfect(int a, int b) { int c, d, e; for (int i = a; i <= b; i++) { e = 0; c = i; for (int j = 1; j < c; j++) { if (c % j == 0) e = e + j; } if (e == c) { cout << e << endl; } }