Enter the Number : 27 The Factors are : 1 3 9 27
This is a C# Program to display the factors of the entered number.
This C# Program Displays the Factors of the Entered Number.
The factors of a number are all those numbers that can divide evenly into the number with no remainder.
Here is source code of the C# program which checks a given integer is odd or even. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Display the Factors of the Entered Number */ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program { class Program { static void Main(string[] args) { int num, x; Console.WriteLine("Enter the Number "); num = int.Parse(Console.ReadLine()); Console.WriteLine("The Factors are : "); for (x = 1; x <= num; x++) { if (num % x == 0) { Console.WriteLine(x); } } Console.ReadLine(); } } }
In this C# program, we are reading the number using ‘num’ variable. Using for loop compute the factors of the entered number, the factors of a number are all those numbers that can divide evenly into the number with no remainder.
If condition statement is used to check the modulus of the value of ‘num’ variable value by the value of ‘x’ variable is equal to 0. If the condition is true then execute the statement and print the factors of the given number.
Enter the Number : 27 The Factors are : 1 3 9 27