Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace mostFactorsCheck
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Input `x` value: ");
- int xVal = Int32.Parse(Console.ReadLine());
- Console.WriteLine("Input `y` value: ");
- int yVal = Int32.Parse(Console.ReadLine());
- int currentFactorsCount;
- int mostFactorsNumber = 0;
- int mostFactorsCount = 0;
- for (int i = xVal; i <= yVal; i++)
- {
- currentFactorsCount = countFactors(i);
- if (currentFactorsCount > mostFactorsCount)
- {
- mostFactorsNumber = i;
- mostFactorsCount = currentFactorsCount;
- }
- }
- Console.WriteLine("Between {0} and {1}, " + mostFactorsNumber + " has the most factors with " + mostFactorsCount + " factors.", xVal, yVal);
- Console.ReadKey();
- }
- public static int countFactors(int x)
- {
- int count = 0;
- for (int i = 1; i <= x; i++)
- {
- if (x % i == 0)
- {
- count++;
- }
- }
- return count;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment