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.
Student
I am Utpal Vishwas from Uttar Pradesh. Have completed my B. Tech. course from MNNIT campus Prayagraj in 2022. I have good knowledge of computer networking.
Sure, 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.