- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# program to display factors of entered number
Firstly, enter the number for which you want the factors −
Console.WriteLine("Enter the Number:"); n = int.Parse(Console.ReadLine());
After that, loop through to find the factors −
for (i = 1; i <= n; i++) { if (n % i == 0) { Console.WriteLine(i); } }
Example
You can try to run the following code to display 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(); } } }
Advertisements