Home > Article > Backend Development > C# program to display factors of input number
First, enter the number you want to factor -
Console.WriteLine("Enter the Number:"); n = int.Parse(Console.ReadLine());
After that, loop to find the factors -
for (i = 1; i <= n; i++) { if (n % i == 0) { Console.WriteLine(i); } }
You can try running the following code to display the factors of a number -
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { class ApplicationOne { static void Main(string[] args) { int n, i; Console.WriteLine("Enter the Number:"); n = int.Parse(Console.ReadLine()); Console.WriteLine("Factors:"); for (i = 1; i <= n; i++) { if (n % i == 0) { Console.WriteLine(i); } } Console.ReadLine(); } } }
The above is the detailed content of C# program to display factors of input number. For more information, please follow other related articles on the PHP Chinese website!