Computer Science, asked by rajmili250, 11 months ago

Write a c++ program to find the perfect numbers between a given range

Answers

Answered by Anonymous
0

Answer:

The Perfect number is equal to the sum of all its positive divisors excluding the number itself. For example: 6 is a Perfect number ( that is, 1 + 2 + 3 = 6 ), 24 is a Perfect number ( that is, 1 + 2 + 4 + 7 + 14 = 28 ) The below given C program to find the perfect numbers between a given range

↫↫↫↫↫ Hope it helps you

Plz mark me brainlist ↬↬↬↬↬

Answered by ShakuntalamGhosh
4

Explanation:

C++ program :

#include <iostream>

using namespace std;

bool isPerfect(int no)

{

int i = 0;

int sum = 0;

while (i++ < no)

{

if (no % i == 0 && i < no)

{

sum += i;

}

}

return sum == no;

}

int main()

{

float first;

float second;

cout << "Enter the first number of the range : " << endl; cin >> first;

cout << "Enter the second number of the range : " << endl; cin >> second;

cout << "Perfect numbers between " << first << " and " << second << " :" << endl;

for (int i = first; i <= second; i++)

{

if (isPerfect(i))

{

cout << i << endl;

}

}

return 0;

}

Hope this helps you

Shakuntalam

Similar questions