Write a program to check if a given number is a perfect number or not.
Write a program to check if a given number is a perfect number or not.
356
14-Jun-2023
Aryan Kumar
15-Jun-2023Sure, here is the C# code to check if a given number is a perfect number or not:
C#
This program first reads a number from the user. Then, it uses a for loop to iterate through all the positive divisors of the number. For each divisor, it adds the divisor to a variable called sum. Finally, it checks if the value of sum is equal to the original number. If it is, then the number is a perfect number. Otherwise, the number is not a perfect number.