Check the given Number is Perfect Or Not Using C#.Net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace perfactnumber
{
class Program
{
static void Main(string[] args)
{
int i, n, sum = 0;
Console.WriteLine("enter the num:");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i < n; i++)
{
if (n % i == 0)
sum = sum + i;
}
if (sum == n)
Console.WriteLine("number is perfect", +n);
else
{
Console.WriteLine("not perfect", +n);
}
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace perfactnumber
{
class Program
{
static void Main(string[] args)
{
int i, n, sum = 0;
Console.WriteLine("enter the num:");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i < n; i++)
{
if (n % i == 0)
sum = sum + i;
}
if (sum == n)
Console.WriteLine("number is perfect", +n);
else
{
Console.WriteLine("not perfect", +n);
}
}
}
}
OutPut :
Sign up here with your email
ConversionConversion EmoticonEmoticon