Posts Tagged ‘C# Smith Number’

C# Smith Number

Posted: January 14, 2016 in Algorithms, C#
Tags: ,

smith a

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number, x, i = 2, sum = 0, sum1 = 0, y;
Console.WriteLine(“Enter number=”);
number = Convert.ToInt32(Console.ReadLine());
x = number;
while (number > 10)
{

sum = sum + number % 10;
number = number / 10;
}

sum = sum + number;
while (x > 1)
{
if ((x % i) == 0)
{
if (i == 2 || i == 3 || i == 5 || i == 7)
{
sum1 = sum1 + i;
x = x / i;
}
else
{
y = i;
while (y > 10)
{
sum1 = sum1 + y % 10;
y = y / 10;

}

sum1 = sum1 + y;
x = x / i;

}
}

else
i++;
}
if (sum == sum1)
Console.Write(“Smith number”);
else
Console.WriteLine(“Not smith number”);
Console.ReadLine();

}
}
}

 

smith numbers

 

 

 

 

 

Advertisements