C# program to display factor of entered number
Here's a C# program that displays the factors of a given number:
using System;
class FactorDisplay
{
static void Main()
{
Console.Write("Enter a number: ");
int number = int.Parse(Console.ReadLine());
Console.WriteLine("Factors of " + number + ":");
for (int i = 1; i <= number; i++)
{
if (number % i == 0)
{
Console.WriteLine(i);
}
}
}
}
In this program, the 'Main' method prompts the user to enter a number. The input is stored in the 'number' variable.
The program then uses a 'for' loop to iterate from 1 to the entered number. Inside the loop, it checks if the current number is a factor of the entered number using the condition 'number % i == 0'. If it is, the program prints the current number, which is a factor of the entered number.
To use this program, you can copy and paste it into a C# development environment, such as Visual Studio, and run it. The program will ask for a number, and then it will display all the factors of that number.