C# Program to Find the Factors of the Given Number


This is a C# Program to display the factors of the entered number.

Problem Description

This C# Program Displays the Factors of the Entered Number.

Problem Solution

The factors of a number are all those numbers that can divide evenly into the number with no remainder.

Program/Source Code

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)
Program Explanation

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.

Runtime Test Cases
Enter the Number : 27
The Factors are : 

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

Participate in C# Programming Certification Contest of the Month Now!
If you wish to look at all C# Programming examples, go to 1000 C# Programs.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.