C# program to check the given number is a perfect number or not
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to check the given number is a perfect number or not, is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
Here, we created a class CheckPerfect that contains two static methods IsPerfect() and Main().
The IsPerfect() method is used to check the given number is perfect or not. Here we find the sum of all divisors of a given number and check the sum of divisors with the number, if both are equal then we return value "true" to the calling method otherwise false will be returned to the calling method.
In the Main() method, we read a positive integer value and then pass the entered number to the IsPerfect() method and then print the appropriate message according to the return value of the IsPerfact() method.