How to find the factors of a number in C#

1 Answer

0 votes
// A factor is a number that divides the given number without a remainder

using System;

public class MyClass
{
	public static void Main(string[] args)
	{
		int n = 24;

		for (int i = 1; i <= n; i++) {
			if (n % i == 0)	{
				Console.Write(i + " ");
			}
		}
	}
}




/*
run:
  
1 2 3 4 6 8 12 24 
  
*/

 



answered Jul 22, 2022 by avibootz
...