programming-examples/c-sharp/Mathematics/C# Program to Check Whether the Entered Number is a Amicable Number or Not.cs
2019-11-15 12:59:38 +01:00

52 lines
1.3 KiB
C#

/*
* C# Program Checks Whether the Entered Number is a Amicable Number or Not
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
{
class Program
{
public static void Main(String[] args)
{
int num1, num2, sum1 = 0, sum2 = 0, i;
Console.WriteLine("Enter First Number : ");
num1 = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Second Number : ");
num2 = int.Parse(Console.ReadLine());
for (i = 1; i < num1; i++)
{
if (num1 % i == 0)
{
sum1 = sum1 + i;
}
}
for (i = 1; i < num2; i++)
{
if (num2 % i == 0)
{
sum2 = sum2 + i;
}
}
if (num1 == sum2 && num2 == sum1)
{
Console.WriteLine("They are a Pair of Amicable Numbers");
Console.ReadLine();
}
else
{
Console.WriteLine("They are not Amicable Numbers");
Console.ReadLine();
}
}
}
}
/*
Enter First Number : 220
Enter Second Number :284
They are a Pair Of Amicable Numbers