In this tutorial, I am going to write a program that will check whether a number is a Perfect Number or Not.

#### After completing this tutorial you will be able to understand:

• Write a Program to check a number is a Perfect Number or not?

## What Is Perfect Number?

In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum).

Here you can see an example in below image.

#### Let’s start writing a Program in C#

Step 1 – Open Visual Studio and create a Console Application using C# with the name PerfectNumberDemo.

Step 2- Navigate to Program.cs file and write the following code into it.
```using System; namespace PerfectNumberDemo { class Program { static void Main(string[] args) { int iNumber, iSum = 0, iTemp; Console.Write("Enter the Number"); iNumber = int.Parse(Console.ReadLine()); iTemp = iNumber; for (int iCount = 1; iCount < iNumber; iCount++) { if (iNumber % iCount == 0) { iSum = iSum + iCount; } } if (iSum == iTemp) { Console.WriteLine("\n The Given number is a Perfect Number"); Console.ReadLine(); } else { Console.WriteLine("\n The Given Number is not a Perfect Number"); Console.ReadLine(); } } } }```
All done now we need to run the application to see the output of the above program.

Abstract Class in C#

Interface in C#

Hope you loved this small session about a simple Program in C#.

Thank You.

• It is appropriate time to make some plans for the longer term and it’s time to be happy. I’ve read this submit and if I could I want to recommend you some attention-grabbing issues or suggestions. Maybe you can write next articles referring to this article. I want to learn even more things about it!|

• I have read so many articles or reviews about the blogger lovers except this paragraph is genuinely a good paragraph, keep it up.|

• Hi, this weekend is good in favor of me, because this moment i am reading this great educational article here at my home.|

• You’re so cool! I do not suppose I have read through anything like that before. So wonderful to discover another person with a few original thoughts on this subject. Seriously.. thanks for starting this up. This website is one thing that is required on the internet, someone with a bit of originality!|

• Hello, i feel that i noticed you visited my blog so i got here to go back the desire?.I’m attempting to to find things to improve my web site!I suppose its adequate to make use of a few of your ideas!!|

• Do you mind if I quote a couple of your posts as long as I provide credit and sources back to your weblog? My website is in the very same area of interest as yours and my visitors would certainly benefit from a lot of the information you present here. Please let me know if this ok with you. Many thanks!|

• For the reason that the admin of this web page is working, no question very shortly it will be famous, due to its feature contents.|

• 471476 342536Rattling excellent information can be identified on internet weblog . 941368

• I’m usually to running a blog and i actually respect your content. The article has really peaks my interest. I’m going to bookmark your website and keep checking for brand new information.

• Awesome post.|