write an algorithm to print perfect numbers between 1 to 100
Answers
Answered by
0
Answer:
For example: 6 is Perfect Number since divisor of 6 are 1, 2 and 3. Sum of its divisor is
1 + 2+ 3 =6
and 28 is also a Perfect Number
since 1+ 2 + 4 + 7 + 14= 28
Other perfect numbers: 496, 8128
Program is written using C++
Explanation:
#include <iostream>
#include <cctype>
using namespace std;
int main(){
int n,i=1,sum=0;
cout << "Enter a number: ";
cin >> n;
while(i<n){
if(n%i==0)
sum=sum+i;
i++;
}
if(sum==n)
cout << i << " is a perfect number\n";
else
cout << i << " is not a perfect number\n";
system("pause");
return 0;
}
if u have any query ask me
please mark me as brainliest.
Similar questions
Chemistry,
7 months ago
English,
7 months ago
Social Sciences,
11 months ago
English,
11 months ago
Biology,
11 months ago