Perfect numbers
using System;
using System.Linq;
public enum Classification
{
Perfect,
Abundant,
Deficient
}
public static class PerfectNumbers{
public static Classification Classify(int number){
if(number < 1) throw new ArgumentOutOfRangeException(nameof(number));
var result = Enumerable.Range(1, number / 2)
.Where(i => number % i == 0).Sum();
if(result < number) return Classification.Deficient;
else if (result > number) return Classification.Abundant;
else return Classification.Perfect;
}
}
0
0
0.000
0 comments